run backgroud task using Quartz scheduler
We are presently using the org.springframework.scheduling.quartz.SchedulerFactoryBean and org.springframework.scheduling.quartz.CronTriggerBean to acheive the job scheduling for a specific cronExpressions and we have a requirement now to trigger a background process on some action ie similar to JMS.
I am looking for options using the quartz scheduler and can i add the task as a job in SchedulerFactoryBean (without specifying the cronexpression)and call it from a Java class ? Help required to explore this option. Thanks in advance
thanks for the reply. I did try this option
this is the spring xml config
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="TEST_SCHEDULER" />
</list>
</property>
<property name="autoStartup"><value>true</value></property>
</bean>
<bean id="TEST_SCHEDULER" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="IN_TEST_SCHEDULER" />
<property name="cronExpression"><value>"00 00 00 ? * MON-FRI"</value></property>
</bean>
<bean name="IN_TEST_SCHEDULER" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.TestScheduler" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="20" />
</map>
</property>
</bean>
calling these statements from a java class
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
Scheduler scheduler = schedulerFactory.getScheduler(); //scheduler is null here ..
scheduler.triggerJob(jobName, jobGroup);
The scheduler is null hence not able to trigger job ..
Inject the org.springframework.scheduling.quartz.SchedulerFactoryBean
bean to your class. Call getScheduler()
method on this bean in order to retrieve the scheduler instance. Use the scheduler to add additional triggers (simple, cron, etc.) for your desired job.
got the solution after exploring few sites and posting it just in case someone like me looks for it in future :)
WebApplicationContext springCtx = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
scheduler = (Scheduler) springCtx.getBean("scheduler");
scheduler.triggerJob("IN_TEST_SCHEDULER", "DEFAULT");
this triggers the required job
链接地址: http://www.djcxy.com/p/23630.html上一篇: JobListener问题[JAVA]
下一篇: 使用Quartz调度程序运行后台任务