KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > examples > example11 > SimpleJob


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.example11;
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.Job;
25 import org.quartz.JobExecutionContext;
26 import org.quartz.JobExecutionException;
27
28 /**
29  * <p>
30  * This is just a simple job that gets fired off many times by example 1
31  * </p>
32  *
33  * @author Bill Kratzer
34  */

35 public class SimpleJob implements Job {
36
37     private static Log _log = LogFactory.getLog(SimpleJob.class);
38
39     // job parameter
40
public static final String JavaDoc DELAY_TIME = "delay time";
41     
42     /**
43      * Empty constructor for job initilization
44      */

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

58     public void execute(JobExecutionContext context)
59         throws JobExecutionException {
60
61         // This job simply prints out its job name and the
62
// date and time that it is running
63
String JavaDoc jobName = context.getJobDetail().getFullName();
64         _log.info("Executing job: " + jobName + " executing at " + new Date JavaDoc());
65         
66         // wait for a period of time
67
long delayTime =
68             context.getJobDetail().getJobDataMap().getLong(DELAY_TIME);
69         try {
70             Thread.sleep(delayTime);
71         } catch (Exception JavaDoc e) {
72         }
73
74         _log.info("Finished Executing job: " + jobName + " at " + new Date JavaDoc());
75     }
76
77 }
Popular Tags