Job scheduling Framework Quartz Learning Notes (vi)-handling when job is ill (throws an exception)

Source: Internet
Author: User
Tags dateformat throw exception

We haven't gone too far to complete a job class because it's closely related to your actual application, but in your job process

What happens if an exception is made? Sir you look down ... .....

------------------------------------I'm a split line------------------------------------------------

If Sir looked at the previous few rotten dregs of the article, will know that the following will first paste code, a job class, a scheduling class.

But this time a little different is not rotten slag, but rotten more slag,-.-

Two job classes: Badjob1.java and Badjob2.java

A scheduling class: Jobexceptionexample.java

Badjob1.java[Java]  View plain copy import java.text.simpledateformat;   import java.util.date;      import org.quartz.disallowconcurrentexecution;   import org.quartz.job;    import org.quartz.jobexecutioncontext;   import org.quartz.jobexecutionexception;    import org.quartz.persistjobdataafterexecution;      @ persistjobdataafterexecution   @DisallowConcurrentExecution    Public class badjob2  implements Job {           @Override         public void execute (jobexecutioncontext context)                 throws JobExecutionException {            //  Task Execution Time             simpledateFormat dateformat = new simpledateformat ("Yyyy-mm-dd hh:mm:ss");            string jobname = context.getjobdetail (). GetKey (). GetName ();           system.out.println ("---"  +  jobname +  "  in [ "  + dateformat.format (New date ()) +  " ]  Execute!!    ")  ;           system.err.println ("---    error occurred in  BadJob  2   ,  will stop running!!   ");           jobexecutionexception e2 =  new jobexecutionexception (New exception ());            //  settings   will automatically   remove   This task trigger, so this task will no longer execute the             //e2.setunschedulealltriggers (True);                      //   Throw exception            throw e2;        }  }  


Badjob2.java [Java]   View plain copy import java.text.simpledateformat;    import java.util.date;      import org.quartz.disallowconcurrentexecution;    import org.quartz.job;   import org.quartz.jobexecutioncontext;   import org.quartz.jobexecutionexception;   import org.quartz.persistjobdataafterexecution;       @PersistJobDataAfterExecution    @DisallowConcurrentExecution    public class badjob2 implements job {           @Override        public void execute (jobexecutioncontext context)                

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.