在 Spring 中使用相同的作业详细信息动态重新安排 CronTriggerBean
我的任务是按照用户从 GUI 指定的计划时间动态生成报告。
我在 Spring 应用程序的应用程序上下文中使用以下代码来每天早上 6 点生成报告。
<bean name="scheduleRptJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.secant.qatool.report.scheduler.ScheduleCroneJob"/>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="scheduleRptJob" />
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
</list>
</property>
</bean>
我使用以下代码从控制器动态更改 cron 表达式。但它不起作用。
String time[] = rptScheduleTime.split(":");
String hours = time[0];
String minutes = time[1];
String croneExp = " 00 " + minutes + " " + hours + " * * ? ";
log.debug("CRONE EXP :: " + croneExp);
cronTrigger.clearAllTriggerListeners();
// Setting the crown expression.
cronTrigger.setCronExpression(croneExp);
Trigger[] triggers = {cronTrigger};
// Code to pause and start the cron trigger.
schedulerFactory.stop();
schedulerFactory.setTriggers(triggers);
schedulerFactory.start();
有人可以帮我如何用动态时间重新安排同一份工作吗?
谢谢,
-Anil Kumar.C
My task is to generate the reports dynamically with the scheduled time specified by the user from the GUI.
I am using the following code in the application context of my application in spring to generate the report daily 6 A.M..
<bean name="scheduleRptJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.secant.qatool.report.scheduler.ScheduleCroneJob"/>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="scheduleRptJob" />
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
</list>
</property>
</bean>
I am changing the cron expression dynamically from the controller with the following code. But it is not working.
String time[] = rptScheduleTime.split(":");
String hours = time[0];
String minutes = time[1];
String croneExp = " 00 " + minutes + " " + hours + " * * ? ";
log.debug("CRONE EXP :: " + croneExp);
cronTrigger.clearAllTriggerListeners();
// Setting the crown expression.
cronTrigger.setCronExpression(croneExp);
Trigger[] triggers = {cronTrigger};
// Code to pause and start the cron trigger.
schedulerFactory.stop();
schedulerFactory.setTriggers(triggers);
schedulerFactory.start();
Could someone please help me how to reschedule the same job with dynamic time.
Thanks,
-Anil Kumar.C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
春季论坛中有一个关于此问题的帖子,他们似乎为您的问题找到了解决方案: http://forum.springsource.org/showthread.php?t=31736
但您可以使用 spring 表达式语言每次从持有 的对象中读取它,而不是手动更改文件中的 cron 表达式价值。
there is a thread in the spring forum about this, and it seams they found a solution for your problem: http://forum.springsource.org/showthread.php?t=31736
but instead of manually change the cron expression in the file you could use the spring expression language to read it each time from your object holding the value.
我发现 这个 线程在其中读取了 cron expr从数据库中获取,然后重新安排作业。您只是不会从数据库读取它,而是根据需要直接从 GUI 传递它。
I have found this thread where they read a cron expr from DB and then reschedule the job. You just wouldn't read it from DB, but pass it directly from GUI as you want.