camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Camel 2.3 - ThreadPool Configuration
Date Fri, 05 Mar 2010 09:42: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="">Camel
2.3 - ThreadPool Configuration</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Claus
     <div class="notificationGreySide">
         <h2><a name="Camel2.3-ThreadPoolConfiguration-DesignNotesforThreadPoolConfiguration"></a>Design
Notes for ThreadPool Configuration</h2>

<p><a href="" rel="nofollow">CAMEL-1588</a>
is the ticket for a new and improved thread pool configuration for Apache Camel. Its intended
for Camel 2.3.</p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-Scope"></a>Scope</h3>

<p>Camel uses thread pool in various places such as <a href="/confluence/display/CAMEL/EIP"
title="EIP">EIP</a> patterns, <a href="/confluence/display/CAMEL/Components" title="Components">Components</a>,
<a href="/confluence/display/CAMEL/Async" title="Async">Async</a> API and whatnot.
The aim is to improved and allow easier to configure those thread pools in a more streamlined
manner. The goal is to offer both a fine grained configuration where you can tweak individual
pools and have more coarse grained configuration with fallback to <em>global</em>
settings etc.</p>

<h4><a name="Camel2.3-ThreadPoolConfiguration-Outsidescope"></a>Outside

<p>Some components provides their own thread pool configuration and management which
Camel of course cannot and should not try to tailor with. For example <a href="/confluence/display/CAMEL/Jetty"
title="Jetty">Jetty</a> is such an example.</p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-UsagesofthreadpoolsinCamel"></a>Usages
of thread pools in Camel</h3>

<p>Currently Camel uses thread pools in <b>camel-core</b> in the following
<ul class="alternate" type="square">
	<li><tt>DefaultComponent</tt> - Optional thread pool for components in
need of such</li>
	<li><tt>DefaultEndpoint</tt> - Optional thread pool for endpoints in need
of such</li>
	<li><tt>DefaultProducerTemplate</tt> - Used by the <a href="/confluence/display/CAMEL/Async"
title="Async">Async</a> API of this template</li>
	<li><tt>ScheduledPollConsumer</tt> - Needs a <tt>ScheduledExecutorService</tt>
to schedule its tasks</li>
	<li><tt>RecipientListDefinition</tt> - The <a href="/confluence/display/CAMEL/Recipient+List"
title="Recipient List">Recipient List</a> EIP pattern</li>
	<li><tt>SplitDefinition</tt> - The <a href="/confluence/display/CAMEL/Splitter"
title="Splitter">Splitter</a> EIP pattern</li>
	<li><tt>ThreadsDefinition</tt> - The <tt>threads</tt> DSL</li>
	<li><tt>ToDefinition</tt> - Used by the <tt>toAsync</tt> variation</li>
	<li><tt>WireTapDefinition</tt> - The <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=WireTap&amp;linkCreation=true&amp;fromPageId=10387717"
class="createlink">WireTap</a> EIP pattern</li>
	<li><tt>MulticastProcessor</tt> - The underlying thread pool</li>
	<li><tt>OnCompletionProcessor</tt> - For sending async on completion routes</li>
	<li><tt>SendAsyncProcessor</tt> - The <tt>toAsync</tt> processor
	<li><tt>ThreadsProcessor</tt> - The underlying thread pool</li>
	<li><tt>WireTapProcessor</tt> - For sending async wire taps</li>
	<li><tt>SedaConsumer</tt> - To support the <tt>concurrentConsumers</tt>
and <tt>multipleConsumers</tt> options (uses separate pools)</li>

<h3><a name="Camel2.3-ThreadPoolConfiguration-Existingconfiguration"></a>Existing

<p>You can configure the thread pool using the <b>setExecutorService</b>
setter methods that usually exists on those places where its in use. Some EIP patterns offer
a <tt>executorServiceRef</tt> option to refer to some pool to be looked up in
the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-UsingdefaultThreadPools"></a>Using
default ThreadPools</h3>

<p>We should use <tt>CachedThreadPool</tt> from the JDK Core as its the
best general purpose pool for many short lived tasks, which is what Camel really does. Processing
many messages in a short live.  <b>DONE</b></p>

<p>Only used SingleExecutorService for background tasks, and ScheduledExecutorService
for scheduled tasks <b>DONE</b></p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-Theproblemwithshutdownandrestartingpools"></a>The
problem with shutdown and restarting pools</h3>

<p>The ExecutorService API does not allow to restart a thread pool, which is PITA. So
we need to find a better strategy for stopping vs. shutdown.<br/>
Currently when we stop we also terminate the threadpool, and then re-create it on start. This
only works for default pools which we can create again.<br/>
But for custom thread pools we have no way to create them again as the pool is already created
when its given to us. </p>

<p>We may have to only shutdown thread pools if CamelContext is stopping. And then if
end user stop a route from JMX we can keep the thread pool around.<br/>
Only issue is the scheduled pool should stop scheduling tasks, which may be a bit more trickier
to avoid.</p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-Managedthreadpool"></a>Managed
thread pool</h3>

<p>Check whether the thread pools is managed by default and avail in JConsole. If not
we should probably at least expose some read-only data about the pools.</p>

<h3><a name="Camel2.3-ThreadPoolConfiguration-SpringFactoryforcreatingcustompools"></a>Spring
Factory for creating custom pools</h3>

<p>Create a Spring XML DSL for defining thread pools using custom options such as corePoolSize,
maxPoolSize, keepAlive, thread name etc.<br/>
     <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