Demonstrates the use of the XML Job Initialization plug-in as well as the History Logging plug-ins
示例:
使用XML来设置Job和Trigger,不在代码中直接写,当执行sched.start();时会自动根据quartz.properties配置初始化,如果配置文件中有指定org.quartz.plugin.jobInitializer.fileNames,则会加载指定XML文件的Job与Trigger内容。
1.quartz.properties指定了org.quartz.plugin.jobInitializer的相关信息:
------------------------------------------------------------------------------------------------------------
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName: TestScheduler
org.quartz.scheduler.instanceId: AUTO
org.quartz.scheduler.skipUpdateCheck: true
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 3
org.quartz.threadPool.threadPriority: 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold: 60000
org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
#org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.useProperties: false
#org.quartz.jobStore.dataSource: myDS
#org.quartz.jobStore.tablePrefix: QRTZ_
#org.quartz.jobStore.isClustered: false
#============================================================================
# Configure Datasources
#============================================================================
#org.quartz.dataSource.myDS.driver: org.postgresql.Driver
#org.quartz.dataSource.myDS.URL: jdbc:postgresql://localhost/dev
#org.quartz.dataSource.myDS.user: jhouse
#org.quartz.dataSource.myDS.password:
#org.quartz.dataSource.myDS.maxConnections: 5
#============================================================================
# Configure Plugins
#============================================================================
org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.class: org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames: quartz_data.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound: true
org.quartz.plugin.jobInitializer.scanInterval: 120
org.quartz.plugin.jobInitializer.wrapInUserTransaction: false
------------------------------------------------------------------------------------------------------------
2.XML中为该scheduler配置了:
TestJob1,关联org.quartz.examples.example10.SimpleJob这个Job类
与它关联的Trigger,TestSimpleTrigger1AtFiveSecondInterval,带misfire-instruction
TestJob2,关联org.quartz.examples.example10.SimpleJob这个Job类
a.TestSimpleTrigger2AtTenSecondIntervalAndFiveRepeats
b.TestCronTrigger2AtEveryMinute,带jobDataMap
c.TestCronTrigger2AtEveryMinuteOnThe45thSecond,带misfire-instruction
------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<pre-processing-commands>
<delete-jobs-in-group>*</delete-jobs-in-group> <!-- clear all jobs in scheduler -->
<delete-triggers-in-group>*</delete-triggers-in-group> <!-- clear all triggers in scheduler -->
</pre-processing-commands>
<processing-directives>
<!-- if there are any jobs/trigger in scheduler of same name (as in this
file), overwrite them -->
<overwrite-existing-data>true</overwrite-existing-data>
<!-- if there are any jobs/trigger in scheduler of same name (as in this
file), and over-write is false, ignore them rather then generating an error -->
<ignore-duplicates>false</ignore-duplicates>
</processing-directives>
<schedule>
<job>
<name>TestJob1</name>
<job-class>org.quartz.examples.example10.SimpleJob</job-class>
</job>
<job>
<name>TestDurableJob</name>
<job-class>org.quartz.examples.example10.SimpleJob</job-class>
<durability>true</durability>
<recover>false</recover>
</job>