我们可以创建一个 Spring ScheduledExecutorTask 池吗?

发布于 2024-10-12 04:27:36 字数 1151 浏览 4 评论 0原文

我想看看是否有可能创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2024-10-19 04:27:36

这个怎么样?

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="someObject" method="someMethod" fixed-delay="5000"/>
</task:scheduled-tasks>

<task:scheduler id="myScheduler" pool-size="10"/>

来源: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html#scheduling-task-namespace-scheduled-tasks

How about this?

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="someObject" method="someMethod" fixed-delay="5000"/>
</task:scheduled-tasks>

<task:scheduler id="myScheduler" pool-size="10"/>

Source: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html#scheduling-task-namespace-scheduled-tasks

紫﹏色ふ单纯 2024-10-19 04:27:36

如果您使用固定速率而不是固定延迟,则操作将恰好在该时间间隔内发生,而不是在下一个操作完成之后发生。我没想到您之后需要(手动)合并它?

如果您不需要在上下文文件中进行显式控制,您可以注释该类:

import org.springframework.stereotype.Service
org.springframework.scheduling.annotation.Scheduled

Class annotation: @Service 
Method annotation: @Scheduled(fixedRate=30000)

Context:

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd

<task:annotation-driven />

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:

import org.springframework.stereotype.Service
org.springframework.scheduling.annotation.Scheduled

Class annotation: @Service 
Method annotation: @Scheduled(fixedRate=30000)

Context:

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd

<task:annotation-driven />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文