I'm reading the Spring 3.0 doc s regarding scheduling. I'm leaning towards Spring's JobDetailBean for Quartz. However, the @Scheduled annotation has captured my eye. It appears this is another way of scheduling task using the Spring Framework. Based on the docs, Spring provides three way of scheduling:
I have no interest in the JDK Timer. Why should I choose @Scheduled over Quartz? (When I mention Quartz I mean using Spring's bean wrapper for Quartz).
Let's say my use case is complex enough that I will be communicating to a third-party web service to import and export data at specified intervals.
Quartz is an order of magnitude more complex than Spring's built in scheduler, including support for persistent, transactional and distributed jobs. It's a bit of a pig, though, even with Spring's API support.
If all you need to is to execute methods on a bean every X seconds, or on a cron schedule, then @Scheduled
(or the various options in Spring's <task>
config schema ) is probably enough
I have to state my own experience regarding use of @Scheduled
versus Quartz
as scheduling implementation in a Spring application.
Scheduling jobs had the following requirements:
Hence, we have to try and use Quartz implementation (version 2.2.3) in order to support persistence of jobs in a database. Some basic conclusions are the following:
JobListener
and TriggerListener
. According to Quartz Documentation
We can use some more and complex feature that it doesn't exist in @Scheduler. for example:
scheduler.standby();
and re schedule it with scheduler.start();
. scheduler.shutdown(true);
and scheduler.shutdown(false);
JobDetail job1 =newJob(MyJobClass.class). withIdentity("job1","group1"). storeDurably(). build();
JobDetail job1 = newJob(MyJobClass.class). withIdentity("job1", "group1"). build();
In Spring you could schedule task by using FixedRate,FixedDelay and cron. But most of the scheduled job requires dynamic handling of execution time. So in this scenario it is better to use Quartz as it provide the option to store scheduled jobs in DBJobstore as well as RAMJobstore.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.