问题
The Spring org.springframework.scheduling.TaskScheduler
is different from the JDK java.util.concurrent.ScheduledExecutorService
in the way that it does not allow scheduling a java.util.concurrent.Callable
with a fixed delay (it can just schedule java.lang.Runnable
s).
Is there a Spring-based alternative to the ScheduledExecutorService
available (that is automatically shut down on context destruction) that supports scheduling Callable
s?
回答1:
If the only thing you need is shutdown, use destroy-method
:
<bean id="threadPool" class="java.util.concurrent.Executors"
factory-method="newFixedThreadPool"
destroy-method="shutdown">
<constructor-arg type="int" value="6"/>
</bean>
Works just fine for us.
PS. You may need to use factory-method="newScheduledThreadPool"
instead.
来源:https://stackoverflow.com/questions/8049211/scheduling-a-java-util-concurrent-callable-through-spring-means