使用ScheduledExecutorService调度
因为job实现了java.util.concurrent.Callable
所以可以基于ScheduledExecutorService进行调度
- 参考代码
Job job = ..;
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(job, 5, TimeUnit.SECONDS);
使用Quartz
包含了一个easybatch-quartz
模块,但是不好的是6.0移除了,但是依然可以学习使用
我们可以通过EasyBatchJob&&EasyBatchJobFactory 方便的集成Quartz
参考资料
https://github.com/j-easy/easy-batch/wiki/job-scheduling
https://github.com/j-easy/easy-batch/blob/master/easy-batch-tutorials/src/main/java/org/jeasy/batch/tutorials/advanced/quartz/Launcher.java
来源:oschina
链接:https://my.oschina.net/u/4385799/blog/3274620