Dont start / stop it all the time, create it once and reuse it, and
stop it when you stop your app.

On Tue, Oct 20, 2015 at 6:17 AM, shylendran.c <shylendra...@gmail.com> wrote:
> Hi,
> I am using camel-code-2.15.2.jar. I have a multi-threaded application where
> I have to send message continuously and I am using
> org.apache.camel.ProducerTemplate. But since it is a multi-threaded, it is
> breaking and getting the below exceptions. So, I've tried with 'static
> synchronized' where everything is working, but we can't go with 'static
> synchronized'. So looking for a solution.
> It is clear that the exception is happening when we have
> ProducerTemplate.start() and stop() when multi-threads are invoking this. We
> have created only one instance of ProducerTemplate.
>
> Is there a way which I can check whether the producer template is already
> 'open' or 'stop'. I see few protected variables, and while debugging I see
> exactly what I am looking.
> Please let me know your opinion on this.
>
> class RMThread implements Runnable {
>
> .......
> .........
> public void run() {
> if (producerTemp != null) {
>
> producerTemp.start();
> producerTemp.sendBodyAndHeaders("zzzz", "", map);
> producerTemp.stop();
> .....
> ......
> }
> }
>
> public class MainClass {
> ....
> ProducerTemplate producerTemplate = null;
> producerTemplate = configureRoutes.getContext().createProducerTemplate();
>
> ServerSocket ss = new ServerSocket(111
> while (true) {
> new Thread(new RMThread(ss.accept(), log, producerTemplate,
> producerTemplate_sendTransferMetrics)).start();
> ....
> }
>
>
> Exceptions::
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: ]
>         at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)
> ....
> Caused by: java.lang.IllegalStateException: Pool not open
>         at
> org.apache.commons.pool.BaseObjectPool.assertOpen(BaseObjectPool.java:140)
> ...
> ....
>
> Thanks,
> Shylendran.C
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5772885.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Reply via email to