1. Common interfaces:
1. Job interface: There is only one method for this interface
void execute(JobExecutionContext context)
The developer implements this interface to define the tasks that need to be performed. The JobExecutionContext class provides various information about the scheduling context.
2. JobDetail: used to describe Job implementation classes and some other static information
3. Trigger: describe the time trigger rules for triggering job execution
4. Calendar: defines a time space that may (or impossible) triggers in association with Trigger. It does not define the real time of the trigger, but is used when the normal Schedule needs to limit the Trigger trigger. Most Calendars contain all the time by default, and the user excludes some time.
5. Scheduler: Run the container and use SchedulerFactory to create a Scheduler instance
2. Code example:
1. When using Quartz, you need to implement the Job interface;
public class TestJob implements Job { public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("Hello World! - " + new Date()); //do more... }}2. Scheduling [It's relatively simple, just look at the code]
public class quartzTest { public static void main(String args[]) throws SchedulerException, ParseException { JobDetail jobDetail= JobBuilder.newJob(TestJob.class) .withIdentity("testJob_1","group_1") .build(); Trigger trigger= TriggerBuilder .newTrigger() .withIdentity("trigger_1","group_1") .startNow() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(10) //Time interval.withRepeatCount(5) //Number of repetitions (6 times will be executed) ) .build(); SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); sched.scheduleJob(jobDetail,trigger); sched.start(); }}Here is the version 2.2.1, refer to the examples of the official documentation. I saw that some reference books are used in older versions, so there are some differences. Many methods have been deprecated, so it is more realistic to read the documents directly. Quartz's official website address is: http://www.quartz-scheduler.org/
III. Quartz2.2.1 configuration file example
# Default Properties file for use by StdSchedulerFactory# to create a Quartz Scheduler Instance, if a different# properties file is not explicitly specified.# #Cluster configuration org.quartz.scheduler.instanceName: DefaultQuartzSchedulerorg.quartz.scheduler.rmi.export: falseorg.quartz.scheduler.rmi.proxy: falseorg.quartz.scheduler.wrapJobExecutionInUserTransaction: false org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount: 10org.quartz.threadPool.threadPriority: 5org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true org.quartz.jobStore.misfireThreshold: 60000 #============================================================================# Configure JobStore#============================================================================================================= #Default configuration, save data to memory#org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore#Permanent configuration org.quartz.jobStore.class:org.quartz.impl.jdbcjobstore.JobStoreTXorg.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegateorg.quartz.jobStore.useProperties:true#Database table prefix org.quartz.jobStore.tablePrefix:qrtz_org.quartz.jobStore.dataSource:qzDS #========================================================================================================================================================= Configure Datasources#====================================================================================================#JDBC driver org.quartz.dataSource.qzDS.driver:com.mysql.jdbc.Driverorg.quartz.dataSour ce.qzDS.URL:jdbc:mysql://localhost:3306/quartzdborg.quartz.dataSource.qzDS.user:rotorg.quartz.dataSource.qzDS.password:123456org.quartz.dataSource.qzDS.maxConnection:10
4. Database related
Persistence requires creating Quartz data tables in the corresponding database in advance. In the Quartz release package, the docs/dbTables has SQL scripts corresponding to different databases.
For example, here is MYSQL:
Data table field explanation: