Job scheduling Framework Quartz Learning Notes (v)--What about the missing tasks?

Source: Internet
Author: User
Tags dateformat sleep

I do not know when you use the quartz is not encountered in such a situation:

Triggers are set to fire every 3 seconds, but the work takes 10 seconds to execute. Therefore, the trigger has missed the trigger before the end of a task execution

How do we deal with this situation, let's study ...

Or do you want to paste the code first:

Job class: Statefuldumbjob.java[Java]  View plain copy import java.text.simpledateformat;   import java.util.calendar;    import org.quartz.disallowconcurrentexecution;   import org.quartz.job;   import org.quartz.jobdatamap;   import org.quartz.jobexecutioncontext;   Import  org.quartz.JobExecutionException;   import org.quartz.persistjobdataafterexecution;       @PersistJobDataAfterExecution    @DisallowConcurrentExecution    Public  class StatefulDumbJob implements Job {           //  static constants, as tasks between calls, keep the Data key (key)        // num_executions, the saved count increments by 1 each time        // execution_delay, the task in the execution of the middle sleep time. In this case, excessive sleep time leads to missed triggers        public static final string num_ executions =  "Numexecutions";      public static final String EXECUTION_DELAY =  " Executiondelay ";           @Override         Public void execute (jobexecutioncontext context)                 throws JobExecutionException {              //  time of task execution             simpledateformat dateformat = new simpledateformat (                     "YYYY-MM-DD HH: Mm:ss ");           String jobRunTime =  Dateformat.format (Calendar.getinstance (). GetTime ());               system.err.println ("---" + context.getjobdetail (). Getkey () getName ()  + "   in   : ["                    +  jobruntime +  "]  carried out!!");               //  Task Execution count   cumulative            jobdatamap map = context.getjobdetail (). Getjobdatamap ();           int executeCount =  0;           if  (Map.containskey (num_executions))  {                executeCount =  Map.getint (num_executions);           }            executeCount++;            map.put (num_executions, executecount);               //  sleep time:  reset value &nbsp by scheduling class; This example is   sleep 10s            long delay = 5000l;            if  (Map.containskey (execution_delay))  {                delay = map.getlong (execution_delay);            }               try {                Thread.Sleep (delay);           } catch  (Exception  ignore)  {           }  

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.