Skip to content

job scheduling

Mahmoud Ben Hassine edited this page Feb 7, 2020 · 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. But you can always schedule jobs with any Java based scheduler like Quartz.

Using Quartz

Easy Batch used to provide a module called easybatch-quartz that acted as bridge between Easy Batch jobs and Quartz jobs. However, this module has been removed starting from v6.0.0. The bridge classes EasyBatchJob and EasyBatchJobFactory can be found in the Quartz tutorial and can be copied if needed. The tutorial shows how to use Quartz to schedule Easy Batch jobs.

Clone this wiki locally