KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > examples > example6 > BadJob2


1 /*
2  * Copyright 2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 package org.quartz.examples.example6;
19
20 import java.util.Date JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.quartz.StatefulJob;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27
28 /**
29  * <p>
30  * A job dumb job that will throw a job execution exception
31  * </p>
32  *
33  * @author Bill Kratzer
34  */

35 public class BadJob2 implements StatefulJob {
36
37     // Logging
38
private static Log _log = LogFactory.getLog(BadJob2.class);
39
40     /**
41      * Empty public constructor for job initilization
42      */

43     public BadJob2() {
44     }
45
46     /**
47      * <p>
48      * Called by the <code>{@link org.quartz.Scheduler}</code> when a <code>{@link org.quartz.Trigger}</code>
49      * fires that is associated with the <code>Job</code>.
50      * </p>
51      *
52      * @throws JobExecutionException
53      * if there is an exception while executing the job.
54      */

55     public void execute(JobExecutionContext context)
56         throws JobExecutionException {
57         String JavaDoc jobName = context.getJobDetail().getFullName();
58         _log.info("---" + jobName + " executing at " + new Date JavaDoc());
59
60         // a contrived example of an exception that
61
// will be generated by this job due to a
62
// divide by zero error
63
try {
64             int zero = 0;
65             int calculation = 4815 / zero;
66         } catch (Exception JavaDoc e) {
67             _log.info("--- Error in job!");
68             JobExecutionException e2 =
69                 new JobExecutionException(e);
70             // Quartz will automatically unschedule
71
// all triggers associated with this job
72
// so that it does not run again
73
e2.setUnscheduleAllTriggers(true);
74             throw e2;
75         }
76
77         _log.info("---" + jobName + " completed at " + new Date JavaDoc());
78     }
79
80 }
Popular Tags