Reputation: 395
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?
Upvotes: 2
Views: 2516
Reputation: 395
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-
Upvotes: 0
Reputation: 10735
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.
Upvotes: 2
Reputation: 29619
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>
Upvotes: 0