我们可以创建一个 Spring ScheduledExecutorTask 池吗?
我想看看是否有可能创建一个 Spring ScheduledExecutor 池。我需要的是设置一个 ScheduledExecutor 任务,它将定期执行某些任务。我试图使用以下方式:
<bean id="contentProcessorPool"
class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
<property name="poolSize" value="${processor.corepoolsize}"/>
<property name="continueScheduledExecutionAfterException" value="true"/>
<property name="scheduledExecutorTasks">
<list>
<ref local="processor"/>
</list>
</property>
<bean id="processor"
class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
<property name="delay" value="${processor.polling.delay}"/>
<property name="period" value="${processor.polling.period}"/>
<property name="runnable">
<ref local="contentWorker" />
</property>
<bean id="contentWorker" class="com.autodesk.contentextraction.processor.ContentWorker">
</bean>
但这会创建一个 ContentWorker 实例,该实例以指定的时间间隔持续运行。我想要的是一组 ContentWorker 在给定的时间间隔后运行。
任何指示都将受到高度赞赏。
谢谢
I'm trying to see if there's a possibility to create a pool of spring ScheduledExecutor. What I need is a set a ScheduledExecutor tasks which will perform certain task in a regular interval. I was trying to use the following way :
<bean id="contentProcessorPool"
class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
<property name="poolSize" value="${processor.corepoolsize}"/>
<property name="continueScheduledExecutionAfterException" value="true"/>
<property name="scheduledExecutorTasks">
<list>
<ref local="processor"/>
</list>
</property>
<bean id="processor"
class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
<property name="delay" value="${processor.polling.delay}"/>
<property name="period" value="${processor.polling.period}"/>
<property name="runnable">
<ref local="contentWorker" />
</property>
<bean id="contentWorker" class="com.autodesk.contentextraction.processor.ContentWorker">
</bean>
But this creates one a single ContentWorker instance which keeps running at the specified interval. What I want is a set of ContentWorker to run after a given interval.
Any pointers will be highly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个怎么样?
来源: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html#scheduling-task-namespace-scheduled-tasks
How about this?
Source: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html#scheduling-task-namespace-scheduled-tasks
如果您使用固定速率而不是固定延迟,则操作将恰好在该时间间隔内发生,而不是在下一个操作完成之后发生。我没想到您之后需要(手动)合并它?
如果您不需要在上下文文件中进行显式控制,您可以注释该类:
Context:
If you used fixed rate instead of fixed delay the operation will occur exactly at that interval, and not after the following one has complete. I wouldn't have thought you'd need to pool it (manually) after that?
If you don't need explicit control in your context file, you can annotate the class:
Context: