views:

97

answers:

3

My application uses Spring 2.5.6. I have a service that creates explicit threads for some specific task. Triggering of this service call happens through quartz time scheduler.

Question :

While executing service calls, i want to use some sort of thread pooler that can return me thread instances. Is there any implementations that i can use in Spring?

A: 

Hi, have you considered using a ThreadPoolTaskExecutor? You can easily configure this using spring, from the doco:

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="queueCapacity" value="25" />
</bean>
krock
+2  A: 

I recommend you to use the java.util.concurrent.ExecutorService class.

You can also use Spring's ThreadPoolTaskExecutor class. Both classes can be configured as ordinary Spring beans.

And since it's just normal Spring bean, you can code against it.

If you upgrade to Spring 3, you have better concurrency support. You can for example declaratively execute a method in an async process with the @Async annotation.

I have written a tutorial about how you can use thread pooling with Spring 3 here.

Espen
thanks... it worked out..
MiKu
A: 

But i have another issue... Somehow it is not accepting the cofig which i am setting to...

<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="100" />
    <property name="maxPoolSize" value="200" />
    <property name="queueCapacity" value="100" />
    <property name="daemon" value="true" />
    <property name="keepAliveSeconds" value="54000" /> 
    <property name="allowCoreThreadTimeOut" value="true" />
    <property name="threadNamePrefix" value="ThreadPoolTaskExecutor For Cron" />
</bean> 

but somehow the things are set to the default ones..

pool size : 0 core pool size : 50 max pool size : 100 deamon : false active count : 0 keep alive seconds : 60 thread prifix : taskExecutor-

MiKu