Scheduling a java.util.concurrent.Callable through Spring means

╄→尐↘猪︶ㄣ 提交于 2019-12-11 23:38:31

问题


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.Runnables).

Is there a Spring-based alternative to the ScheduledExecutorService available (that is automatically shut down on context destruction) that supports scheduling Callables?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!