Spring JDBC存储SchedulerFactoryBean无法手动触发存储的触发器

时间:2013-04-23 12:21:49

标签: spring quartz-scheduler

我有一个集群的Quartz(版本2.1.6)调度程序,在部署到websphere集群时似乎工作正常。调度程序由Spring(版本3.1.3_RELEASE)创建。

<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);

但它也不起作用。 有人可以帮助我吗

1 个答案:

答案 0 :(得分:0)

我自己发现了这个问题。 调度程序未在事务中正确执行。

我为调度程序添加了<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>
相关问题