2017-06-22 41 views
0

經過大量搜索後,我還沒有遇到任何解決方案。 我在springjob.xml中用spring批處理調度程序調度我的作業。SpringBatch調度程序多次執行

<bean id="startScheduler" class="com.myapp.MyServiceStart" /> 
<task:scheduler id="myScheduler" pool-size="1"/> 
<task:scheduled-tasks scheduler="myScheduler"> 
     <task:scheduled ref="startScheduler" method="runMyService" cron="*/5 * * * * *" /> 
</task:scheduled-tasks> 

但runMyService啓動多次,並隨着每個wchduled重新運行而增加。我需要我的服務在每次計劃重新運行時運行一次。

+0

'cron'表達式看起來無效。期望的執行間隔是多少? –

+0

看起來你有太多的*。試試'*/5 * * * *' – yogidilip

回答

0

可能一個原因是再次執行後他們重新計劃。所以下一個計劃取決於執行時間。

public ScheduledFuture<?> schedule() { 
     synchronized (this.triggerContextMonitor) { 
      this.scheduledExecutionTime = this.trigger.nextExecutionTime(this.triggerContext); 
      if (this.scheduledExecutionTime == null) { 
       return null; 
      } 
      long initialDelay = this.scheduledExecutionTime.getTime() - System.currentTimeMillis(); 
      this.currentFuture = this.executor.schedule(this, initialDelay, TimeUnit.MILLISECONDS); 
      return this; 
     } 
    } 
public void run() { 
     Date actualExecutionTime = new Date(); 
     super.run(); 
     Date completionTime = new Date(); 
     synchronized (this.triggerContextMonitor) { 
      this.triggerContext.update(this.scheduledExecutionTime, actualExecutionTime, completionTime); 
      if (!this.currentFuture.isCancelled()) { 
       schedule(); 
      } 
     } 
    }