It’s not a good way to create a new ProducerTemplate per request. If you can reuse the ProducerTemplate you don’t need to worry about the threads which are in the wait states, because that is how the thread pool works. If you are don’t comfortable with that, you can pass an executor which is manageable from your side to the ProducerTemplate.
-- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (English) http://jnn.iteye.com (Chinese) Twitter: willemjiang Weibo: 姜宁willem On April 4, 2014 at 11:30:29 AM, Saran ([email protected]) wrote: > Hi Willem Jiang, > > Thanks for your reply, the link below says that Spring container will > handle starting and stopping of producer template. > > https://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html > > > I think i will have to explain more now, along with EJB service, HTTP, SOAP > and JMS services are supported in our product. In case of HTTP and SOAP > service, i am able to set time out since its a camel http component. > Where as for EJB, i am not able to handle it, hence i found using > Future will support in setting time out. > > Using this approach i am able to handle time out cases, but when i look at > the thread dump i see all producer template threads are in waiting state. > But if i manually start and stop the producer template instead of using > Spring to inject it, i don't see any producer template threads in waiting > state and there are as many number of producer template instances created > and stopped and resources are released. > > Is it right to create producer template instances for every request, start > and stop them manually, in this way i don't see any producer template > threads in waiting state? > > Below is the trace > > java.lang.Thread.State: WAITING > at sun.misc.Unsafe.park(Native Method) > - parking to wait for (a > java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) > at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) > at > java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) > > at > java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) > at > java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067) > > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127) > > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) > > at java.lang.Thread.run(Thread.java:744) > > Locked ownable synchronizers: > - None > > > > > > > On Fri, Apr 4, 2014 at 6:05 AM, Willem Jiang wrote: > > > If you use ProducerTemplate a lot, my suggestion is you can consider to > > set an Executor yourself to the ProducerTemplate which you get from the > > Spring. Then you can have a full control of it. > > > > BTW, I don’t think Spring can stop the ProducerTemplate if the > > ApplicationContext is not closed. > > > > -- > > Willem Jiang > > > > Red Hat, Inc. > > Web: http://www.redhat.com > > Blog: http://willemjiang.blogspot.com (English) > > http://jnn.iteye.com (Chinese) > > Twitter: willemjiang > > Weibo: 姜宁willem > > > > > > > > On April 3, 2014 at 9:27:43 PM, [email protected] ( > > [email protected]) wrote: > > > To handle timeout on client side for EJB service call, i used Future and > > had > > > set time out time over future object. Having this, both success and time > > out cases are > > > working fine. > > > > > > But the problem here is when i take thread dump i could see that the > > thread is in waiting > > > state. > > > When i manually stop and start producer template there are no threads in > > waiting state. > > > As per camel guidelines if i allow Spring to inject Producer Template, > > starting, stopping > > > and releasing resources will be handled by Spring itself, but i am not > > sure whether the > > > resources are released as the thread is in waiting state. > > > > > > Or is there a better way to handle time out? If its a HTTP request, > > camel-http component > > > has options to set timeout and not in case of camel-ejb component. > > > > > > Any suggestions will be of a great help as we are fine tuning out > > product's performance > > > and most of the thread's waiting are related to Camel Producer Template > > only. > > > > > > _____________________________________ > > > Sent from http://camel.465427.n5.nabble.com > > > > > > > > > > > > > -- > Cheers, > Arthanarisamy >
