需要动态设置quartz cron表达式

编程入门 行业动态 更新时间:2024-10-28 14:34:45
本文介绍了需要动态设置quartz cron表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的 web 应用程序(Servlet web 应用程序)中使用石英,下面是石英.property 文件和石英.job.xml 的快照

I'm using quartz in my web application (Servlet web app) following is snap of quartz.property file and the quartz.job.xml

quartz.property

quartz.property

#=================================================== # Configure the Job Initialization Plugin #=================================================== org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin org.quartz.plugin.jobInitializer.fileNames = jobs.xml org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.jobInitializer.scanInterval = 10 org.quartz.plugin.jobInitializer.wrapInUserTransaction = false <?xml version='1.0' encoding='utf-8'?> <job-scheduling-data xmlns="www.quartz-scheduler/xml/JobSchedulingData" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="www.quartz-scheduler/xml/JobSchedulingData www.quartz-scheduler/xml/job_scheduling_data_1_8.xsd" version="1.8"> <schedule> <job> <name>my-very-clever-job</name> <group>MYJOB_GROUP</group> <description>The job description</description> <job-class>com.acme.scheduler.job.ReportJob</job-class> </job> <trigger> <cron> <name>my-trigger</name> <group>MYTRIGGER_GROUP</group> <job-name>my-very-clever-job</job-name> <job-group>MYJOB_GROUP</job-group> <!-- trigger every night at 4:30 am --> <cron-expression>0 30 4 * * ?</cron-expression> </cron> </trigger> </schedule> </job-scheduling-data>

一切正常,按此顺序.我需要允许用户按照他们想要的方式更改时间(cron 表达式).我的问题是如何动态设置 cron 表达式.

Every thing work fine,in this order. I need to allow user to change the time (cron expression) as the way they want.My question is how do i set the cron expression in dynamically.

推荐答案

CronTrigger cronTrigger = (CronTrigger) stdScheduler .getTrigger(triggerName,triggerGroupName); CronTrigger newTriggerIns = new CronTrigger(); newTriggerIns.setJobName(cronTrigger.getJobName()); newTriggerIns.setName(triggerName); newTriggerIns.setCronExpression(newCronExpression); stdScheduler.rescheduleJob(triggerName,triggerGroupName,newTriggerIns);

在上面,采用现有的触发器实例.创建一个新的触发器实例并设置 cron 表达式.

In the above, take the existing trigger instance. Create one new trigger instance and set cron expression.

然后使用新实例重新安排现有实例.

Then reschedule the existing instance with new one.

更多推荐

需要动态设置quartz cron表达式

本文发布于:2023-11-24 08:37:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624499.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   动态   quartz   cron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!