Skip to content

job scheduling

Mahmoud Ben Hassine edited this page Jun 4, 2017 · 2 revisions

Using a ScheduledExecutorService

Easy Batch jobs implement the java.util.concurrent.Callable interface so they can be easily scheduled using a java.util.concurrent.ScheduledExecutorService:

Job job = ..;
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(job, 5, TimeUnit.SECONDS);

In this example, the job will be scheduled to run in 5 seconds. The advantage of java.util.concurrent.ScheduledExecutorService is that it allows you to schedule jobs without requiring any third party library. But this service is limited in terms of scheduling features. For example, it does not support cron expressions. That's why Easy Batch provides an extension to schedule jobs with the popular Java scheduler Quartz.

Using Quartz

The JobScheduler API provided in the easybatch-quartz module allows you to schedule job execution:

  • At a fixed point of time using scheduleAt(Job job, Date when)
  • Repeatedly with predefined interval using scheduleAtWithInterval(Job job, Date when, int interval)
  • Using unix cron-like expression with scheduleCron(Job job, String cronExpression)

Clone this wiki locally