Spring,Java—并行运行多个计划任务,每个任务运行一个实例

Spring,Java—并行运行多个计划任务,每个任务运行一个实例,java,spring,scheduled-tasks,Java,Spring,Scheduled Tasks,我尝试并行运行多个计划任务,每个任务一个实例 我像这样配置任务 <task:scheduled ref="PatchData" method="start" fixed-rate="1000"/> 但是,有许多实例每秒启动一次,而第一个实例尚未完成。是否可以同时只配置任务运行的一个实例? spring-scheduler.xml中的我的bean配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt

我尝试并行运行多个计划任务,每个任务一个实例 我像这样配置任务

<task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>

但是,有许多实例每秒启动一次,而第一个实例尚未完成。是否可以同时只配置任务运行的一个实例? spring-scheduler.xml中的我的bean配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/task
            http://www.springframework.org/schema/task/spring-task-3.2.xsd">


    <bean id="UpdateScheduler" class="org.ws.scheduled.UpdateScheduler" />
    <bean id="PatchData" class="org.ws.scheduled.PatchData" />

    <task:scheduled-tasks scheduler="myScheduler">
           <task:scheduled ref="UpdateScheduler" method="start" cron="0 30 14 * * *"/>            
           <task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>

    </task:scheduled-tasks>

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


您可以在bean标记中添加配置文件设置。例如:

<beans profile="scheduledProfile">
 <bean id="UpdateScheduler" class="org.ws.scheduled.UpdateScheduler" />
 <bean id="PatchData" class="org.ws.scheduled.PatchData" />

 <task:scheduled-tasks scheduler="myScheduler">
      <task:scheduled ref="UpdateScheduler" method="start" cron="0 30 14 * * *"/>            
      <task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>
 </task:scheduled-tasks>
<bean />

并且,在一台机器上启动应用程序,并激活计划配置文件=
-Dspring.profiles.active=scheduledProfile


这样,此计划只适用于一个实例。

也许您想要的是固定延迟而不是固定速率?如果在多次加载上下文的同时启动了多个实例,请参阅。如果希望每次运行一个实例,请使用
固定延迟
而不是
固定速率