You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Manish K Bafna <Ma...@headstrong.com> on 2009/01/14 09:32:59 UTC

Thread pool for Camelcontext

Hello,
Is there a way to provide a Thread pool to the camel context so that threads of the polling consumers can be managed? Right now, every polling consumer is running on a different threads and therefore if there are many routes, many threads are created.

Thanks,
Manish.


 
***The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review,retransmission,dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.***

Re: Thread pool for Camelcontext

Posted by achalam <aa...@gmail.com>.
Hi Christian,
We are proving an implementation for ThreadPoolFactory using the Spring
WorkManagerTaskExecutor like this:
WorkManagerTaskExecutor taskExecutor = new WorkManagerTaskExecutor();
taskExecutor.setWorkManager(getWorkManager());
taskExecutor.setWorkListener(getWorkListener());
ExecutorServiceAdapter executorServiceAdapter = new
ExecutorServiceAdapter(taskExecutor);

This is working fine for newThreadPool which returns an ExecutorService.

I am not sure, what should be the implementation for newScheduledThreadPool
method which returns ScheduledExecutorService, since I do not see an
implementation of ScheduledExecutorService in SPring 3.0.4.
BTW, we are using WebSphere7.1 and Camel2.9 and Spring3.0.4

Thanks,
AChalam



--
View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5724431.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Thread pool for Camelcontext

Posted by "christian.ohr" <ch...@googlemail.com>.
A custom ThreadPoolFactory could be sufficient:
As I have a similar task (although I decided to stick with Camel-managed
tasks for the time being), I prototyped an ExecutorService-to-WorkManager
bridge, i.e. an ExecutorService that delegates Runnables/Callables as
commonj Work objects to a WorkManager instance, and the returning the
resulting WorkItem back as a Future. A custom ThreadPoolFactory would return
these ExecutorService instances instead ones provided by
DefaultTHreadPoolFactory.

I must admit this is far from being stable (especially the corresponding
ScheduledExecutorService/Timer bridge), but it would also be applicable to
other frameworks that rely on ExecutorService.
If there's interest in this, I can pursue this a bit further.

cheers
Christian


--
View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5713358.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Thread pool for Camelcontext

Posted by dj5483 <dj...@gmail.com>.
Claus,
I will look into contributing an update.  Can the documentation be updated
to reflect the fact that it's the ExecutorServiceManager that needs to be
implemented?  The documentation seems to indicate that all you need to do is
implement a new ThreadPoolFactory.  This seems misleading.


Claus Ibsen-2 wrote
> 
> On Tue, May 22, 2012 at 4:53 AM, dj5483 &lt;dj5483@&gt; wrote:
>> Claus,
>> I too am implementing a Camel (2.9.1) project on WebSphere (7.0.0.19).
>> After reading the Camel Docs it was clear to me that I was supposed to
>> implement the ThreadPoolFactory interface and declare a Spring Bean to
>> allow
>> Camel to wire in my implementation.  After attempting to implement the
>> ThreadPoolFactory on my own I began to look for help and found this user
>> board.  The code that Preben has supplied turned out to be quite useful.
>>  It
>> seems to me though, that there is a gap in the Camel API.  The
>> ThreadPoolFactory interface provides methods that operate on a
>> ThreadFactory.  I believe the ThreadFactory is the appropriate place to
>> tie
>> into the CommonJ WorkManager, not the ThreadPoolFactory.  The
>> DefaultExecutorServiceManager uses a private method to create new
>> instances
>> of a ThreadFactory (CamelThreadFactory).  It seems like the ThreadFactory
>> should also be able to be injected.  This would allow us to easily
>> override
>> the mechanism that is creating the individual threads.  Is there
>> something
>> that I am missing with the ThreadPoolFactory?
>>
> 
> Well the idea is really that you implement it *all* when you do custom
> threading in WAS etc.
> However if you want to extend the default impls in Camel, we can
> possible turn private methods in protected etc.
> 
> As usual we love contributions.
> 
> 
>>
>> Claus Ibsen-2 wrote
>>>
>>> Hi
>>>
>>> You need to implement
>>> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ThreadPoolFactory.html
>>> and then configure camel to use your impl on the ExecutorServiceManager
>>>
>>> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ExecutorServiceManager.html#setThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory)
>>>
>>> The latter can be auto detected by Camel if you in the Spring XML file
>>> just define your custom thread pool factory.
>>> As these bean types can do that:
>>> http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
>>>
>>> On Tue, Feb 21, 2012 at 3:11 AM, achalam &lt;aadi.chalam@&gt; wrote:
>>>> Hi,
>>>> We are using camel 2.9 with Springframework3.0.4 and Websphere 7.1 .
>>>> How
>>>> do
>>>> we configure, the camel, so that we use the managed threads in the
>>>> application. I know the configuration in spring, to use the
>>>> workmanager,
>>>> but
>>>> somehow, not able to understand how it is done in the context of camel.
>>>>
>>>> Thanks,
>>>> Adi
>>>>
>>>> --
>>>> View this message in context:
>>>> http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5500895.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> FuseSource
>>> Email: cibsen@
>>> Web: http://fusesource.com
>>> Twitter: davsclaus, fusenews
>>> Blog: http://davsclaus.blogspot.com/
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5713248.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Email: cibsen@
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 


--
View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5713337.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Thread pool for Camelcontext

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 22, 2012 at 4:53 AM, dj5483 <dj...@gmail.com> wrote:
> Claus,
> I too am implementing a Camel (2.9.1) project on WebSphere (7.0.0.19).
> After reading the Camel Docs it was clear to me that I was supposed to
> implement the ThreadPoolFactory interface and declare a Spring Bean to allow
> Camel to wire in my implementation.  After attempting to implement the
> ThreadPoolFactory on my own I began to look for help and found this user
> board.  The code that Preben has supplied turned out to be quite useful.  It
> seems to me though, that there is a gap in the Camel API.  The
> ThreadPoolFactory interface provides methods that operate on a
> ThreadFactory.  I believe the ThreadFactory is the appropriate place to tie
> into the CommonJ WorkManager, not the ThreadPoolFactory.  The
> DefaultExecutorServiceManager uses a private method to create new instances
> of a ThreadFactory (CamelThreadFactory).  It seems like the ThreadFactory
> should also be able to be injected.  This would allow us to easily override
> the mechanism that is creating the individual threads.  Is there something
> that I am missing with the ThreadPoolFactory?
>

Well the idea is really that you implement it *all* when you do custom
threading in WAS etc.
However if you want to extend the default impls in Camel, we can
possible turn private methods in protected etc.

As usual we love contributions.


>
> Claus Ibsen-2 wrote
>>
>> Hi
>>
>> You need to implement
>> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ThreadPoolFactory.html
>> and then configure camel to use your impl on the ExecutorServiceManager
>>
>> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ExecutorServiceManager.html#setThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory)
>>
>> The latter can be auto detected by Camel if you in the Spring XML file
>> just define your custom thread pool factory.
>> As these bean types can do that:
>> http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
>>
>> On Tue, Feb 21, 2012 at 3:11 AM, achalam &lt;aadi.chalam@&gt; wrote:
>>> Hi,
>>> We are using camel 2.9 with Springframework3.0.4 and Websphere 7.1 . How
>>> do
>>> we configure, the camel, so that we use the managed threads in the
>>> application. I know the configuration in spring, to use the workmanager,
>>> but
>>> somehow, not able to understand how it is done in the context of camel.
>>>
>>> Thanks,
>>> Adi
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5500895.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cibsen@
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5713248.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Thread pool for Camelcontext

Posted by dj5483 <dj...@gmail.com>.
Claus,
I too am implementing a Camel (2.9.1) project on WebSphere (7.0.0.19). 
After reading the Camel Docs it was clear to me that I was supposed to
implement the ThreadPoolFactory interface and declare a Spring Bean to allow
Camel to wire in my implementation.  After attempting to implement the
ThreadPoolFactory on my own I began to look for help and found this user
board.  The code that Preben has supplied turned out to be quite useful.  It
seems to me though, that there is a gap in the Camel API.  The
ThreadPoolFactory interface provides methods that operate on a
ThreadFactory.  I believe the ThreadFactory is the appropriate place to tie
into the CommonJ WorkManager, not the ThreadPoolFactory.  The
DefaultExecutorServiceManager uses a private method to create new instances
of a ThreadFactory (CamelThreadFactory).  It seems like the ThreadFactory
should also be able to be injected.  This would allow us to easily override
the mechanism that is creating the individual threads.  Is there something
that I am missing with the ThreadPoolFactory?


Claus Ibsen-2 wrote
> 
> Hi
> 
> You need to implement
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ThreadPoolFactory.html
> and then configure camel to use your impl on the ExecutorServiceManager
> 
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ExecutorServiceManager.html#setThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory)
> 
> The latter can be auto detected by Camel if you in the Spring XML file
> just define your custom thread pool factory.
> As these bean types can do that:
> http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
> 
> On Tue, Feb 21, 2012 at 3:11 AM, achalam &lt;aadi.chalam@&gt; wrote:
>> Hi,
>> We are using camel 2.9 with Springframework3.0.4 and Websphere 7.1 . How
>> do
>> we configure, the camel, so that we use the managed threads in the
>> application. I know the configuration in spring, to use the workmanager,
>> but
>> somehow, not able to understand how it is done in the context of camel.
>>
>> Thanks,
>> Adi
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5500895.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
> 

--
View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5713248.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Thread pool for Camelcontext

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You need to implement
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ThreadPoolFactory.html
and then configure camel to use your impl on the ExecutorServiceManager

http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/ExecutorServiceManager.html#setThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory)

The latter can be auto detected by Camel if you in the Spring XML file
just define your custom thread pool factory.
As these bean types can do that:
http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html

On Tue, Feb 21, 2012 at 3:11 AM, achalam <aa...@gmail.com> wrote:
> Hi,
> We are using camel 2.9 with Springframework3.0.4 and Websphere 7.1 . How do
> we configure, the camel, so that we use the managed threads in the
> application. I know the configuration in spring, to use the workmanager, but
> somehow, not able to understand how it is done in the context of camel.
>
> Thanks,
> Adi
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5500895.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Thread pool for Camelcontext

Posted by achalam <aa...@gmail.com>.
Hi,
We are using camel 2.9 with Springframework3.0.4 and Websphere 7.1 . How do
we configure, the camel, so that we use the managed threads in the
application. I know the configuration in spring, to use the workmanager, but
somehow, not able to understand how it is done in the context of camel.

Thanks,
Adi

--
View this message in context: http://camel.465427.n5.nabble.com/Thread-pool-for-Camelcontext-tp470625p5500895.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Thread pool for Camelcontext

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Each component has a setExecutorService where you can inject the ThreadPool.

But I dont think you can set it on the CamelContext so every component
will default use the one you have defined. But its a good idea if you
for instance runs in a managed environment such as WebSphere where you
can define thread pools.

There was a topic on this user forum about the WebSphere stuff
recently. Try search a little.

And feel free to create a ticket in JIRA for the configuration of the
executor service on CamelContext.

Have I missed something? Maybe you can do something smart with Spring
and have it autowired?


On Wed, Jan 14, 2009 at 9:32 AM, Manish K Bafna
<Ma...@headstrong.com> wrote:
> Hello,
> Is there a way to provide a Thread pool to the camel context so that threads of the polling consumers can be managed? Right now, every polling consumer is running on a different threads and therefore if there are many routes, many threads are created.
>
> Thanks,
> Manish.
>
>
>
> ***The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review,retransmission,dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.***
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/