Dynamic change of quartz scheduling time (2)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.