camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Threading Model
Date Sun, 21 Mar 2010 13:40:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Threading
     <h4>Page <b>edited</b> by             <a href="">Claus
     <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>

<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;

<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-Createcustomthreadpool"></a>Create custom thread
<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>

     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message