Schedule java batch job with interval from last end date

640 views Asked by At

I wrote my job using jsr-352 and deployed it on wildfly. How can I schedule one job with some delay after last end time like below time line where = is execution time and - is delay time:

===============--=====--========--

Note: maximum number of job execution is one

1

There are 1 answers

3
cheng On

JBeret ejb scheduler supports repeating interval job executions, with a fixed interval duration or certain delay duration after the start of job execution. Delay after end of a job execution is currently not supported. If your job execution duration is relatively predictable, you can approximate it with either interval or delay after the start of a job execution.

To achieve this kind of job schedulgin with finer control, you can try the following:

  • schedule a single-action job schedule
  • configure a job listener in job.xml to watch for the end of the above job execution, and scheule the next single-action job execution with a short initial delay
  • specifically, the job listener's afterJob() method should be able to look up or inject TimerSchedulerBean, which is a local singleton EJB, and invoke its org.jberet.schedule.TimerSchedulerBean#schedule method. The job listener is reponsible for creating an instance of org.jberet.schedule.JobScheduleConfig, passing it when calling the ejb business method. The job listener should already have all info to create JobScheduleConfig.