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

Java 我们可以创建一个Spring ScheduledExecutorTask池吗?,java,spring,scheduled-tasks,Java,Spring,Scheduled Tasks,我想看看是否有可能创建一个spring ScheduledExecutor池。我需要的是一组ScheduledExecutor任务,它将在固定的时间间隔内执行某些任务。我试着用以下方法: <bean id="contentProcessorPool" class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean"> <property name="poolSize" value

我想看看是否有可能创建一个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>



但这将创建一个ContentWorker实例,该实例将以指定的时间间隔保持运行。我想要的是一组ContentWorker在给定的时间间隔后运行

任何提示都将受到高度赞赏

谢谢

这个怎么样

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

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


来源:

如果您使用固定利率而不是固定延迟,则操作将恰好在该间隔发生,而不是在下一个间隔完成后发生。我没想到在那之后你会需要(手动)把它集中起来

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

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

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

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 />
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
import org.springframework.stereotype.Service
org.springframework.scheduling.annotation.Scheduled

Class annotation: @Service 
Method annotation: @Scheduled(fixedRate=30000)
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 />