我目前使用下面的配置在spring下运行Quartz。使用数据库作为调度程序后端的原因是启用集群模式。
这一切都运行正常,但如果我想删除InitialAbstractPublicationJob我有问题。让我们说删除下面的所有配置,除了调度程序本身。 DB表QRTZ_TRIGGERS中仍存在一行。
TRIGGER_NAME: initialAbstractTrigger
TRIGGER_GROUP: DEFAULT
JOB_NAME: initialAbstractDataAccessDelegator
JOB_GROUP: DEFAULT
IS_VOLATILE: 0
DESCRIPTION: NULL
NEXT_FIRE_TIME: 1330953433511
PREV_FIRE_TIME: 1330953432511
TRIGGER_STATE: WAITING
TRIGGER_TYPE: SIMPLE
START_TIME: 1330953336511
END_TIME: 0
CALENDAR_NAME: NULL
MISFIRE_INSTR: 0
JOB_DATA: NULL
1 row in set (0.00 sec)
这一行导致quartz尝试加载SpringPublicationJobBean,它在Spring中不再存在,并且异常比比皆是。所以我的问题是:是否可以配置调度程序在关闭或启动spring时从数据库刷新触发器,并从spring applicationContext.xml重新创建触发器
<bean id="initialAbstractPublicationJob" class="bbc.forge.ibroadcast.snowball.InitialAbstractPublicationJob" />
<bean id="initialAbstractDataAccessDelegator" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="bbc.forge.ibroadcast.snowball.DelegatingJobBean"/>
<property name="durability" value="false" />
<property name="jobDataAsMap">
<map>
<entry key="job.bean.name" value="initialAbstractPublicationJob" >
</entry>
<entry key="sdtl.file.prefix" value="sdtl_" >
</entry>
</map>
</property>
</bean>
<bean id="initialAbstractTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
see the example of method invoking job above
<property name="jobDetail" ref="initialAbstractDataAccessDelegator" />
10 seconds
<property name="startDelay" value="0" />
repeat every n milliseconds
<property name="repeatInterval" value="1000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="initialAbstractTrigger" />
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
</props>
</property>
</bean>
答案 0 :(得分:1)
您可以使用XMLSchedulingDataProcessorPlugin
在单独的XML文件中存储作业并触发配置。此文件可以在启动时覆盖现有作业 :
<?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_2_0.xsd ">
<processing-directives>
<overwrite-existing-data>true</overwrite-existing-data>
<ignore-duplicates>true</ignore-duplicates>
</processing-directives>
</job-scheduling-data>
有关插件的更多信息,请参阅Configure Scheduler Plugins文档参考。
答案 1 :(得分:0)
重复的问题:delete-trigger-in-quartz
如果你想在春季关机时更新触发器,只需在@PreDestroy方法中执行这些操作。