Spring timer dynamically sets the timer time

Source: Internet
Author: User

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.



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.