Spring JDBC存储SchedulerFactoryBean无法手动触发存储的触发器
问题描述:
我有一个集群Quartz(版本2.1.6)调度程序,似乎在部署到websphere集群时可以正常工作。调度器由Spring创建(版本3.1.3_RELEASE)。Spring JDBC存储SchedulerFactoryBean无法手动触发存储的触发器
<bean id="scheduler-JDBC" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" abstract="true">
<property name="dataSource" ref="myDataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="jobFactory">
<bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory" />
</property>
<property name="overwriteExistingJobs" value="true" />
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">${org.quartz.jobStore.driverDelegateClass}</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
</props>
</property>
</bean>
<bean id="cronScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" parent="scheduler-${scheduler:RAM}" depends-on="quartzDatabaseInitializer">
<property name="startupDelay" value="10" />
<property name="autoStartup" value="true" />
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="triggers">
<list>
<ref bean="cronTriggerStats" />
</list>
</property>
</bean>
触发器和作业存储在数据库中。作业是使用job_name =“serverStatsJob”和job_group =“DEFAULT”创建的。触发器每20分钟执行一次。 如何手动触发作业?
我已经试过
StdScheduler cronScheduler = (StdScheduler)springContext.getBean("cronScheduler");
cronScheduler.triggerJob(new JobKey("serverStatsJob", "DEFAULT"));
如果我使用一个RAM存储,而不是JDBC其中工程
我也试图与存储的作业
Trigger trigger1 = newTrigger()
.withIdentity("serverStatsJobTrigger", "userRequested")
.withSchedule(simpleSchedule()
.withRepeatCount(0))
.startNow()
.forJob(new JobKey("serverStatsJob", "DEFAULT"))
.build();
cronScheduler.scheduleJob(trigger1);
但是,创造一个新的触发它也不起作用。 有人能帮我吗
答
我自己发现了这个问题。 调度程序未正确执行事务。
我为调度程序添加了<tx:advice>
,现在它工作。
<aop:config>
<aop:pointcut id="quartzSchedulerPointcut" expression="execution(* org.quartz.Scheduler.*(..))" />
<aop:advisor advice-ref="quartzSchedulerAdvice" pointcut-ref="quartzSchedulerPointcut" />
</aop:config>
<tx:advice id="quartzSchedulerAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>