Spring timer dynamically sets the timer time
Spring Quartz timer dynamically sets the timer time1. Configure the Spring configuration file (frams-quartz-context.xml ):
DoTimingSendTimer
1 0 0 1 1? 2099
2. Set the scheduled time Action (TimingSendTimerAction)
/***** Function Description: timed delivery ** Creator: Gansuper ** Creation Time: **/public class TimingSendTimerAction {/*** Service injection */@ Autowired @ Qualifier ("timingSendTimerService") private TimingSendTimerService timingSendTimerService;/*** function description: run the timed delivery operation ** input parameter: ** output parameter: ** Creation Time: */public void doTimingSendTimer () {System. out. println ("timed delivery starts! "); This. timingSendTimerService. doTimingSendTimer (); System. out. println (" timed delivery completed! ");}}
3. Set the scheduled time Service interface implementation class
/*** Function Description: Set the delivery time. service Interface implementation class ** created by Gansuper **: **/@ Service ("setTimingSendTimeService ") public class extends BaseServiceImpl implements SetTimingSendTimeService {/*** workOrderInfoDAO */private TWorkOrderInfoDAO workOrderInfoDAO;/*** scheddao */privateScheduler schedments; /*** set the delivery time */@ Overridepublic void setTimingSendTime () {try {if (sch Edtex= = null | workOrderInfoDAO = null) {scheddao = (schedtil) SpringContextUtil. getBean ("strQuartz"); workOrderInfoDAO = (TWorkOrderInfoDAO) SpringContextUtil. getBean ("workOrderInfoDAO");} CronTriggerBean trigger = (CronTriggerBean) schedger. getTrigger ("timingSendTimerTrigger", schedgger. DEFAULT_GROUP); String sendTime = this. workOrderInfoDAO. queryTimingSendTime (); // obtain the time value to be set in the database if (sendTime = Null) {return;} sendTime = sendTime. substring (0, sendTime. lastIndexOf (". "); String [] sendTimes = sendTime. split ("") [1]. split (":"); String pushTime = sendTimes [2] + "" + sendTimes [1] + "" + sendTimes [0] + "**? "; Trigger. setCronExpression (pushTime); // sets the timer trigger time schedpression. rescheduleJob ("timingSendTimerTrigger", schedgger. DEFAULT_GROUP, trigger);} catch (SchedulerException e) {e. printStackTrace ();} catch (java. text. parseException e) {e. printStackTrace () ;}} public Scheduler getScheduler () {return scheduler;} public void setScheduler (Scheduler scheduler) {this. scheduler = scheddao;} public TWorkOrderInfoDAO getWorkOrderInfoDAO () {return workOrderInfoDAO;} public void setWorkOrderInfoDAO (TWorkOrderInfoDAO workOrderInfoDAO) {this. workOrderInfoDAO = workOrderInfoDAO ;}}
4. Enter the time value to be set at the front-end and save it to the corresponding table in the database through related operations. After the scheduled time is successfully saved, call the setTimingSendTime () method. After completing the preceding steps, you can dynamically set the timing time.