In the dynamic change of quartz scheduling time (1), using the Delete job and then reloading to implement dynamic change scheduling cycle, today, I carefully read the next Quartz API, found that another way to achieve this function.
Version:
1.8.6
RELATED links:
api:http://quartz-scheduler.org/api/1.8.0/
Http://quartz-scheduler.org/documentation/quartz-1.x/cookbook/UpdateTrigger
Related methods:
Reschedulejob
Reschedulejob (String triggername,
String groupname,
Trigger Newtrigger)
throws Schedulerexception
Remove (delete) The Trigger with the given name, and store the new given One-which must is associated with the same job (The new trigger must have the job name & group specified)-however, the new trigger need not have the same name as T He's old trigger.
(Delete the trigger for the given name and save the new trigger, the name of the old and new trigger is not the same.) Parameters: triggername-the name of the Trigger to be replaced. (Name of the trigger to replace) groupname-the group name of th e Trigger to be replaced. (Name of the group in which the trigger is being replaced) newtrigger-the new Trigger to be stored. (new Trigger) Returns: null if a T Rigger with the given name & Group is not found and removed from the store, otherwise the ' the ' The ' fire ' Y scheduled trigger. Throws: Schedulerexception
Specific code:
/** * Dynamically modifying the execution period of a task * @param jobName Task Name * @param time Execution cycle * @throws schedulerexception * @throws parseexception */public static Boolean Modifyjobtime (String jobName, String time) throws Schedulerexception, parseexception{Bo
Olean flag = false;
Scheduler sched = Sf.getscheduler ();
Jobdetail Jobdetail = Sched.getjobdetail (JobName, job_group_name);
if (jobdetail!= null) {Trigger Trigger = (crontrigger) Sched.gettrigger (Jobdetail.getname (), job_trigger_group_name);
if (trigger!= null) {Crontrigger Ctrigger = (Crontrigger) trigger;
String timeold = Ctrigger.getcronexpression ();
if (!timeold.equalsignorecase (time)) {System.out.println ("Modify task:" +jobname+ "Now:" +time);
Modify trigger Ctrigger.setcronexpression (time); /** * UPDATE trigger * Sched.reschedulejob (triggername, Triggergroupname, newtrigger) * * * Sched.reschedul
Ejob (JobName, Job_trigger_group_name, Ctrigger);
Flag = true; }}} return Flag; }
Note: sched.reschedulejob (JobName, Job_trigger_group_name, Ctrigger); here JobName is triggername, the values are the same.