camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Threading Model
Date Sun, 21 Mar 2010 13:53:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Threading+Model">Threading
Model</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="ThreadingModel-ThreadingModel"></a>Threading Model</h2>
<p><b>Available as of Camel 2.3</b></p>

<p>The threading model in Camel is based on leveraging the JDK concurrency API which
provides thread pools, named <tt>ExecutorService</tt>.</p>

<p>Camel leverages thread pools in the following places:</p>
<ul class="alternate" type="square">
	<li>several <a href="/confluence/display/CAMEL/EIP" title="EIP">EIP</a>
patterns supports using thread pools for concurrency</li>
	<li><a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a> component
for asynchronous connectivity</li>
	<li><a href="/confluence/display/CAMEL/Async" title="Async">Threads DSL</a>
in the Camel route</li>
	<li><a href="/confluence/display/CAMEL/ServicePool" title="ServicePool">ServicePool</a>
for pooling services</li>
	<li>And some component provide thread pools by nature such as <a href="/confluence/display/CAMEL/JMS"
title="JMS">JMS</a>, <a href="/confluence/display/CAMEL/Jetty" title="Jetty">Jetty</a></li>
</ul>


<h3><a name="ThreadingModel-Threadpoolprofiles"></a>Thread pool profiles</h3>
<p>By default when a thread pool is to be created then its based on the default thread
pool profile which is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    &lt;threadPoolProfile id=<span class="code-quote">"defaultThreadPoolProfile"</span>
defaultProfile=<span class="code-quote">"true"</span>
                       poolSize=<span class="code-quote">"10"</span> maxPoolSize=<span
class="code-quote">"20"</span> maxQueueSize=<span class="code-quote">"1000"</span>
                       rejectedPolicy=<span class="code-quote">"CallerRuns"</span>/&gt;
</pre>
</div></div>

<p>What that means is that for example when you use <a href="/confluence/display/CAMEL/Multicast"
title="Multicast">Multicast</a> with <tt>parallelProcessing=true</tt>
enabled, then it would create a thread pool based on the profile above. The <tt>rejectedPolicy</tt>
have four options: <tt>Abort, CallerRuns, Discard, DiscardOldest</tt> which corresponds
to the same four options provided out of the box in the JDK. </p>

<p>You can define as many thread pool profiles as you like. But there must only <b>one</b>
default profile. A custom thread pool profile will inherit from the default profile. Which
means that any option you do not explicit define will fallback and use the option from the
default profile.</p>

<p>You can use <tt>-1</tt> in maxQueueSize to indicate a unbounded queue.</p>

<p>In Java DSL you can configure the default thread pool profile from the <tt>ExecutorServiceStartegy</tt>
which you access from <tt>CamelContext</tt>.</p>

<h3><a name="ThreadingModel-Usingthreadpoolprofiles"></a>Using thread pool
profiles</h3>

<p>Suppose you want to use a custom thread pool profile for a Multicast EIP pattern
in a Camel route you can do it using the <tt>executorServiceRef</tt> attribute
as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;camelContext ...&gt;</span>
    ...
    &lt;threadPoolProfile id=<span class="code-quote">"fooProfile"</span>

                       poolSize=<span class="code-quote">"20"</span> maxPoolSize=<span
class="code-quote">"50"</span> maxQueueSize=<span class="code-quote">"-1"</span>/&gt;
    ...

    <span class="code-tag">&lt;route&gt;</span>
       ...
       <span class="code-tag">&lt;multicast strategyRef=<span class="code-quote">"myStrategy"</span>
executorServiceRef=<span class="code-quote">"fooProfile"</span>&gt;</span>
          ...
       <span class="code-tag">&lt;/multicast&gt;</span>
      ...
    <span class="code-tag">&lt;route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>
<p>What Camel will do at runtime is to lookup in the <a href="/confluence/display/CAMEL/Registry"
title="Registry">Registry</a> for a <tt>ExecutorService</tt> with the
id = fooProfile. If none found it will fallback and see if there is a <tt>ThreadPoolProfile</tt>
defined with that id. And in this example there is and so the profile is used for creating
a new <tt>ExecutorService</tt> which is handed back to the <a href="/confluence/display/CAMEL/Multicast"
title="Multicast">Multicast</a> EIP to use in the route.</p>

<h3><a name="ThreadingModel-Createcustomthreadpool"></a>Create custom thread
pool</h3>
<p>You can also use the &lt;threadPool/&gt; tag in Spring XML to create a specific
thread pool (eg <tt>ExecutorService</tt>). Notice that any options you do not
explicit define, will have Camel to use the default thread pool profile as fallback. For example
if you omit setting the <tt>maxQueueSize</tt> then Camel will fallback and use
the value from the default thread pool profiles, which by default is 1000. </p>

<h3><a name="ThreadingModel-Management"></a>Management</h3>
<p>All the thread pools that Camel creates are managed and thus you can see them in
JConsole under the <tt>threadpools</tt> category.</p>

<h3><a name="ThreadingModel-ExecutorServiceStrategy"></a>ExecutorServiceStrategy</h3>
<p>Camel provides a pluggable strategy to hook in your own thread pool provider, for
example from a WorkManager in a J2EE server etc.<br/>
See the <tt>org.apache.camel.spi.ExecutorServiceStrategy</tt> interface which
you should implement and hook into the WorkManager.</p>

<p>See <a href="/confluence/display/CAMEL/Advanced+configuration+of+CamelContext+using+Spring"
title="Advanced configuration of CamelContext using Spring">Advanced configuration of CamelContext
using Spring</a> for how to configure it.</p>

<p>You can configure it on the <tt>CamelContext</tt> from Java DSL using
the getter/setter.</p>

<h3><a name="ThreadingModel-Componentdevelopers"></a>Component developers</h3>
<p>If you develop your own Camel component and are in need of a thread pool, then its
advised to use the <tt>ExecutorServiceStrategy</tt> to create the thread pool
you need. </p>

<h3><a name="ThreadingModel-Shutdown"></a>Shutdown</h3>
<p>All thread pools created by Camel will be properly shutdown when <tt>CamelContext</tt>
shutdowns which ensures no leaks in the pools in case you run in a server environment with
hot deployments and the likes.</p>

<h3><a name="ThreadingModel-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Architecture" title="Architecture">Architecture</a></li>
	<li><a href="/confluence/display/CAMEL/Async" title="Async">Async</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Threading+Model">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=14813422&revisedVersion=4&originalVersion=3">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Threading+Model?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message