Commits

wkratzer  committed 544fd22

Reviewed by: James House
Details: Reorganized old examples and added new examples. Each example now resides in its own package.

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@3569f7d36a-ea1c-0410-88ea-9fd03e4c9665

  • Participants
  • Parent commits dbb6a1d

Comments (0)

Files changed (31)

File quartz_1x/src/java/examples/org/quartz/examples/example1/HelloJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example1;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * This is just a simple job that says "Hello" to the world.
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class HelloJob implements Job {
+
+	private static Log _log = LogFactory.getLog(HelloJob.class);
+
+	/**
+	 * <p>
+	 * Empty constructor for job initilization
+	 * </p>
+	 * <p>
+	 * Quartz requires a public empty constructor so that the
+	 * scheduler can instantiate the class whenever it needs.
+	 * </p>
+	 */
+	public HelloJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// Say Hello to the World and display the date/time
+		_log.info("Hello World! - " + new Date());
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example1/SimpleExample.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example1;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SimpleTrigger;
+import org.quartz.helpers.TriggerUtils;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * This Example will demonstrate how to start and shutdown the Quartz 
+ * scheduler and how to schedule a job to run in Quartz.
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleExample {
+
+	
+	public void run() throws Exception {
+		Log log = LogFactory.getLog(SimpleExample.class);
+
+		log.info("------- Initializing ----------------------");
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		log.info("------- Initialization Complete -----------");
+
+		log.info("------- Scheduling Jobs -------------------");
+
+		// computer a time that is on the next round minute
+		Date runTime = TriggerUtils.getEvenMinuteDate(new Date());
+
+		// define the job and tie it to our HelloJob class
+		JobDetail job = new JobDetail("job1", "group1", HelloJob.class);
+		
+		// Trigger the job to run on the next round minute
+		SimpleTrigger trigger = 
+			new SimpleTrigger("trigger1", "group1", runTime);
+		
+		// Tell quartz to schedule the job using our trigger
+		sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() + " will run at: " + runTime);  
+
+		// Start up the scheduler (nothing can actually run until the 
+		// scheduler has been started)
+		sched.start();
+		log.info("------- Started Scheduler -----------------");
+
+		// wait long enough so that the scheduler as an opportunity to 
+		// run the job!
+		log.info("------- Waiting 90 seconds... -------------");
+		try {
+			// wait 90 seconds to show jobs
+			Thread.sleep(90L * 1000L); 
+			// executing...
+		} catch (Exception e) {
+		}
+
+		// shut down the scheduler
+		log.info("------- Shutting Down ---------------------");
+		sched.shutdown(true);
+		log.info("------- Shutdown Complete -----------------");
+	}
+
+	public static void main(String[] args) throws Exception {
+
+		SimpleExample example = new SimpleExample();
+		example.run();
+
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example10/PlugInExample.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example10;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * This example will spawn a large number of jobs to run
+ * 
+ * @author James House, Bill Kratzer
+ */
+public class PlugInExample {
+
+    public void run() throws Exception {
+    	Log log = LogFactory.getLog(PlugInExample.class);
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+        log.info("------- Initialization Complete -----------");
+
+        log.info("------- (Not Scheduling any Jobs - relying on XML definitions --");
+
+        log.info("------- Starting Scheduler ----------------");
+
+        // start the schedule 
+        sched.start();
+
+        log.info("------- Started Scheduler -----------------");
+
+        log.info("------- Waiting five minutes... -----------");
+
+        // wait five minutes to give our jobs a chance to run
+        try {
+            Thread.sleep(300L * 1000L); 
+        } 
+        catch (Exception e) {
+        }
+
+        // shut down the scheduler
+        log.info("------- Shutting Down ---------------------");
+        sched.shutdown(true);
+        log.info("------- Shutdown Complete -----------------");
+
+        SchedulerMetaData metaData = sched.getMetaData();
+        log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+    }
+
+    public static void main(String[] args) throws Exception {
+
+    	PlugInExample example = new PlugInExample();
+		example.run();
+    }
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example10/SimpleJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example10;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * This is just a simple job that gets fired off many times by example 1
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleJob implements Job {
+
+	private static Log _log = LogFactory.getLog(SimpleJob.class);
+
+	/**
+	 * Empty constructor for job initilization
+	 */
+	public SimpleJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+		_log.info("Executing job: " + jobName + " executing at " + new Date());
+		
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example11/LoadExample.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example11;
+
+import java.util.Date;
+
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.SimpleTrigger;
+import org.quartz.impl.StdSchedulerFactory;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * This example will spawn a large number of jobs to run
+ * 
+ * @author James House, Bill Kratzer
+ */
+public class LoadExample {
+
+	private int _numberOfJobs = 500;
+	
+	public LoadExample(int inNumberOfJobs) {
+		_numberOfJobs = inNumberOfJobs;
+	}
+	
+    public void run() throws Exception {
+    	Log log = LogFactory.getLog(LoadExample.class);
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+        log.info("------- Initialization Complete -----------");
+
+        log.info("------- (Not Scheduling any Jobs - relying on XML definitions --");
+
+        String schedId = sched.getSchedulerInstanceId();
+
+        // schedule 500 jobs to run
+        for (int count=1; count <= _numberOfJobs; count++) {
+            JobDetail job = new JobDetail("job" + count, "group1",
+                    SimpleJob.class);
+            // tell the job to wait one minute (60 seconds)
+            job.getJobDataMap().put(SimpleJob.DELAY_TIME, 60000L);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            SimpleTrigger trigger = new SimpleTrigger("trigger_" + count, "group_1");
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 10000L
+                    + (count * 100)));
+            sched.scheduleJob(job, trigger);
+            if (count % 25 == 0) {
+            	log.info("...scheduled " + count + " jobs");
+            }
+        }
+        
+        
+        log.info("------- Starting Scheduler ----------------");
+
+        // start the schedule 
+        sched.start();
+
+        log.info("------- Started Scheduler -----------------");
+
+        log.info("------- Waiting five minutes... -----------");
+
+        // wait five minutes to give our jobs a chance to run
+        try {
+            Thread.sleep(300L * 1000L); 
+        } 
+        catch (Exception e) {
+        }
+
+        // shut down the scheduler
+        log.info("------- Shutting Down ---------------------");
+        sched.shutdown(true);
+        log.info("------- Shutdown Complete -----------------");
+
+        SchedulerMetaData metaData = sched.getMetaData();
+        log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+    }
+
+    public static void main(String[] args) throws Exception {
+
+    	int numberOfJobs = 500;
+    	if (args.length == 1) {
+    		numberOfJobs = Integer.parseInt(args[0]);
+    	}
+    	if (args.length > 1) {
+    		System.out.println(
+    				"Usage: java " + 
+    				LoadExample.class.getName() + 
+    				"[# of jobs]");
+    		return;
+    	}
+    	LoadExample example = new LoadExample(numberOfJobs);
+		example.run();
+    }
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example11/SimpleJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example11;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * This is just a simple job that gets fired off many times by example 1
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleJob implements Job {
+
+	private static Log _log = LogFactory.getLog(SimpleJob.class);
+
+	// job parameter
+	public static final String DELAY_TIME = "delay time";
+	
+	/**
+	 * Empty constructor for job initilization
+	 */
+	public SimpleJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+		_log.info("Executing job: " + jobName + " executing at " + new Date());
+		
+        // wait for a period of time
+		long delayTime = 
+			context.getJobDetail().getJobDataMap().getLong(DELAY_TIME);
+        try {
+            Thread.sleep(delayTime); 
+        } 
+        catch (Exception e) {
+        }		
+
+        _log.info("Finished Executing job: " + jobName + " at " + new Date());
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example12/RemoteClientExample.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example12;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.CronTrigger;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * This example is a client program that will remotely 
+ * talk to the scheduler to schedule a job.   In this 
+ * example, we will need to use the JDBC Job Store.  The 
+ * client will connect to the JDBC Job Store remotely to 
+ * schedule the job.
+ * 
+ * @author James House, Bill Kratzer
+ */
+public class RemoteClientExample {
+
+    public void run() throws Exception {
+
+		Log log = LogFactory.getLog(RemoteClientExample.class);
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		// define the job and ask it to run
+        JobDetail job = 
+        	new JobDetail("remotelyAddedJob", "default", SimpleJob.class);
+        JobDataMap map = new JobDataMap();
+        map.put("msg", "Your remotely added job has executed!");
+        job.setJobDataMap(map);
+        CronTrigger trigger = new CronTrigger(
+        		"remotelyAddedTrigger", "default",
+                "remotelyAddedJob", "default", 
+                new Date(), 
+                null, 
+                "/5 * * ? * *");
+
+        // schedule the job
+        sched.scheduleJob(job, trigger);
+
+		log.info("Remote job scheduled.");
+    }
+
+    public static void main(String[] args) throws Exception {
+
+		RemoteClientExample example = new RemoteClientExample();
+		example.run();
+    }
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example12/RemoteServerExample.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example12;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * @author Bill Kratzer
+ * 
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
+ */
+public class RemoteServerExample {
+
+	/**
+	 * This example will spawn a large number of jobs to run
+	 * 
+	 * @author James House, Bill Kratzer
+	 */
+	public void run() throws Exception {
+		Log log = LogFactory.getLog(RemoteServerExample.class);
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		log.info("------- Initialization Complete -----------");
+
+		log.info("------- (Not Scheduling any Jobs - relying on a remote client to schedule jobs --");
+
+		log.info("------- Starting Scheduler ----------------");
+
+		// start the schedule
+		sched.start();
+
+		log.info("------- Started Scheduler -----------------");
+
+		log.info("------- Waiting ten minutes... ------------");
+
+		// wait five minutes to give our jobs a chance to run
+		try {
+			Thread.sleep(600L * 1000L);
+		} catch (Exception e) {
+		}
+
+		// shut down the scheduler
+		log.info("------- Shutting Down ---------------------");
+		sched.shutdown(true);
+		log.info("------- Shutdown Complete -----------------");
+
+		SchedulerMetaData metaData = sched.getMetaData();
+		log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+	}
+
+	public static void main(String[] args) throws Exception {
+
+		RemoteServerExample example = new RemoteServerExample();
+		example.run();
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example12/SimpleJob.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example12;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * A dumb implementation of Job, for unittesting purposes.
+ * </p>
+ * 
+ * @author James House
+ */
+public class SimpleJob implements Job {
+
+    public static final String MESSAGE = "msg";
+
+	private static Log _log = LogFactory.getLog(SimpleJob.class);
+
+	/**
+	 * Quartz requires a public empty constructor so that the
+	 * scheduler can instantiate the class whenever it needs.
+	 */
+	public SimpleJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+
+		String message = (String) context.
+			getJobDetail().getJobDataMap().get(MESSAGE);
+
+		_log.info("SimpleJob: " + jobName + " executing at " + new Date());
+		_log.info("SimpleJob: msg: " + message);
+	}
+
+	
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example13/ClusterExample.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example13;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SimpleTrigger;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * Used to test/show the clustering features of JDBCJobStore (JobStoreTX or
+ * JobStoreCMT).
+ * 
+ * <p>
+ * All instances MUST use a different properties file, because their instance
+ * Ids must be different, however all other properties should be the same.
+ * </p>
+ * 
+ * <p>
+ * If you want it to clear out existing jobs & triggers, pass a command-line
+ * argument called "clearJobs".
+ * </p>
+ * 
+ * <p>
+ * You should probably start with a "fresh" set of tables (assuming you may
+ * have some data lingering in it from other tests), since mixing data from a
+ * non-clustered setup with a clustered one can be bad.
+ * </p>
+ * 
+ * <p>
+ * Try killing one of the cluster instances while they are running, and see
+ * that the remaining instance(s) recover the in-progress jobs. Note that
+ * detection of the failure may take up to 15 or so seconds with the default
+ * settings.
+ * </p>
+ * 
+ * <p>
+ * Also try running it with/without the shutdown-hook plugin registered with
+ * the scheduler. (org.quartz.plugins.management.ShutdownHookPlugin).
+ * </p>
+ * 
+ * <p>
+ * <i>Note:</i> Never run clustering on separate machines, unless their
+ * clocks are synchronized using some form of time-sync service (daemon).
+ * </p>
+ * 
+ * @see DumbRecoveryJob
+ * 
+ * @author James House
+ */
+public class ClusterExample {
+
+	private static Log _log = LogFactory.getLog(ClusterExample.class);
+	
+	public void cleanUp(Scheduler inScheduler) throws Exception {
+        _log.warn("***** Deleting existing jobs/triggers *****");
+
+        // unschedule jobs
+        String[] groups = inScheduler.getTriggerGroupNames();
+        for (int i = 0; i < groups.length; i++) {
+            String[] names = inScheduler.getTriggerNames(groups[i]);
+            for (int j = 0; j < names.length; j++)
+            	inScheduler.unscheduleJob(names[j], groups[i]);
+        }
+
+        // delete jobs
+        groups = inScheduler.getJobGroupNames();
+        for (int i = 0; i < groups.length; i++) {
+            String[] names = inScheduler.getJobNames(groups[i]);
+            for (int j = 0; j < names.length; j++)
+            	inScheduler.deleteJob(names[j], groups[i]);
+        }
+	}
+	
+    public void run(boolean inClearJobs, boolean inScheduleJobs) 
+    	throws Exception {
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+		
+		if (inClearJobs) {
+			cleanUp(sched);
+		}
+
+		_log.info("------- Initialization Complete -----------");
+
+        if (inScheduleJobs) {
+
+            _log.info("------- Scheduling Jobs ------------------");
+
+            String schedId = sched.getSchedulerInstanceId();
+
+            int count = 1;
+
+            JobDetail job = new JobDetail("job_" + count, schedId,
+                    SimpleRecoveryJob.class);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            SimpleTrigger trigger = 
+            	new SimpleTrigger("triger_" + count, schedId, 20, 5000L);
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 1000L));
+    		_log.info(job.getFullName() +
+    				" will run at: " + trigger.getNextFireTime() +  
+    				" and repeat: " + trigger.getRepeatCount() + 
+    				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+            sched.scheduleJob(job, trigger);
+
+            count++;
+            job = new JobDetail("job_" + count, schedId, 
+            		SimpleRecoveryJob.class);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            trigger = new SimpleTrigger("trig_" + count, schedId, 20, 5000L);
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 2000L));
+    		_log.info(job.getFullName() +
+    				" will run at: " + trigger.getNextFireTime() +  
+    				" and repeat: " + trigger.getRepeatCount() + 
+    				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+            sched.scheduleJob(job, trigger);
+
+            count++;
+            job = new JobDetail("job_" + count, schedId,
+                    SimpleRecoveryStatefulJob.class);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            trigger = new SimpleTrigger("trig_" + count, schedId, 20, 3000L);
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 1000L));
+    		_log.info(job.getFullName() +
+    				" will run at: " + trigger.getNextFireTime() +  
+    				" and repeat: " + trigger.getRepeatCount() + 
+    				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+            sched.scheduleJob(job, trigger);
+
+            count++;
+            job = new JobDetail("job_" + count, schedId, SimpleRecoveryJob.class);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            trigger = new SimpleTrigger("trig_" + count, schedId, 20, 4000L);
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 1000L));
+            _log.info(job.getFullName() + " will run at: "
+                    + trigger.getNextFireTime() + " & repeat: "
+                    + trigger.getRepeatCount() + "/"
+                    + trigger.getRepeatInterval());
+            sched.scheduleJob(job, trigger);
+
+            count++;
+            job = new JobDetail("job_" + count, schedId, SimpleRecoveryJob.class);
+            // ask scheduler to re-execute this job if it was in progress when
+            // the scheduler went down...
+            job.setRequestsRecovery(true);
+            trigger = new SimpleTrigger("trig_" + count, schedId, 20, 4500L);
+            trigger.setStartTime(new Date(System.currentTimeMillis() + 1000L));
+            _log.info(job.getFullName() + " will run at: "
+                    + trigger.getNextFireTime() + " & repeat: "
+                    + trigger.getRepeatCount() + "/"
+                    + trigger.getRepeatInterval());
+            sched.scheduleJob(job, trigger);
+        }
+
+        // jobs don't start firing until start() has been called...
+        _log.info("------- Starting Scheduler ---------------");
+        sched.start();
+        _log.info("------- Started Scheduler ----------------");
+
+        _log.info("------- Waiting for one hour... ----------");
+        try {
+            Thread.sleep(3600L * 1000L);
+        } 
+        catch (Exception e) {
+        }
+
+        _log.info("------- Shutting Down --------------------");
+        sched.shutdown();
+        _log.info("------- Shutdown Complete ----------------");
+    }
+
+    public static void main(String[] args) throws Exception {
+        boolean clearJobs = false;
+        boolean scheduleJobs = true;
+
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].equalsIgnoreCase("clearJobs")) {
+            	clearJobs = true;            	
+            }
+            else if (args[i].equalsIgnoreCase("dontScheduleJobs")) {
+            	scheduleJobs = false;
+            }
+        }
+
+        ClusterExample example = new ClusterExample();
+        example.run(clearJobs, scheduleJobs);
+    }
+}
+

File quartz_1x/src/java/examples/org/quartz/examples/example13/SimpleRecoveryJob.java

+/*
+ * Copyright (c) 2004-2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ * Previously Copyright (c) 2001-2004 James House
+ */
+package org.quartz.examples.example13;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * A dumb implementation of Job, for unittesting purposes.
+ * </p>
+ * 
+ * @author James House
+ */
+public class SimpleRecoveryJob implements Job {
+
+	private static Log _log = LogFactory.getLog(SimpleRecoveryJob.class);
+
+	private static final String COUNT = "count";
+	
+	/**
+	 * Quartz requires a public empty constructor so that the
+	 * scheduler can instantiate the class whenever it needs.
+	 */
+	public SimpleRecoveryJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		String jobName = context.getJobDetail().getFullName();
+
+		// if the job is recovering print a message
+        if (context.isRecovering()) {
+            _log.info("SimpleRecoveryJob: " + jobName + " RECOVERING at " + new Date());
+        }
+        else {
+            _log.info("SimpleRecoveryJob: " + jobName + " starting at " + new Date());
+        }
+
+        // delay for ten seconds
+        long delay = 10L * 1000L;
+        try {
+        	Thread.sleep(delay);
+        }
+        catch (Exception e) {
+        }
+
+        JobDataMap data = context.getJobDetail().getJobDataMap();
+        int count;
+        if (data.containsKey(COUNT)) {
+        	count = data.getInt(COUNT);
+        }
+        else {
+        	count = 0;
+        }
+        count++;
+        data.put(COUNT, count);
+        
+        _log.info("SimpleRecoveryJob: " + jobName + 
+        		" done at " + new Date() + 
+        		"\n Execution #" + count);
+         
+	}
+
+	
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example13/SimpleRecoveryStatefulJob.java

+/*
+ * Created on Mar 6, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.quartz.examples.example13;
+
+import org.quartz.StatefulJob;
+
+/**
+ * This job has the same functionality of SimpleRecoveryJob
+ * except that this job implements the StatefulJob interface
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleRecoveryStatefulJob
+	extends SimpleRecoveryJob
+	implements StatefulJob {
+
+	/**
+	 * 
+	 */
+	public SimpleRecoveryStatefulJob() {
+		super();
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example2/SimpleJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example2;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * This is just a simple job that gets fired off many times by example 1
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleJob implements Job {
+
+	private static Log _log = LogFactory.getLog(SimpleJob.class);
+
+	/**
+	 * Empty constructor for job initilization
+	 */
+	public SimpleJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+		_log.info("SimpleJob says: " + jobName + " executing at " + new Date());
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example2/SimpleTriggerExample.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example2;
+
+import java.util.Date;
+
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.SimpleTrigger;
+import org.quartz.helpers.TriggerUtils;
+import org.quartz.impl.StdSchedulerFactory;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * This Example will demonstrate all of the basics of scheduling capabilities
+ * of Quartz using Simple Triggers.
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleTriggerExample {
+
+	
+	public void run() throws Exception {
+		Log log = LogFactory.getLog(SimpleTriggerExample.class);
+
+		log.info("------- Initializing -------------------");
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		log.info("------- Initialization Complete --------");
+
+		log.info("------- Scheduling Jobs ----------------");
+
+		// jobs can be scheduled before sched.start() has been called
+
+		// get a "nice round" time a few seconds in the future...
+		long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime();
+
+		// job1 will only fire once at date/time "ts"
+		JobDetail job = new JobDetail("job1", "group1", SimpleJob.class);
+		SimpleTrigger trigger = 
+			new SimpleTrigger("trigger1", "group1", new Date(ts));
+
+		// schedule it to run!
+		Date ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		// job2 will only fire once at date/time "ts"
+		job = new JobDetail("job2", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger2", "group1", "job2", "group1",
+				new Date(ts), null, 0, 0);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		// job3 will run 11 times (run once and repeat 10 more times)
+		// job3 will repeat every 10 seconds (10000 ms)
+		job = new JobDetail("job3", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger3", "group1", "job3", "group1",
+				new Date(ts), null, 10, 10000L);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+		
+		// the same job (job3) will be scheduled by a another trigger
+		// this time will only run every 70 seocnds (70000 ms)
+		trigger = new SimpleTrigger("trigger3", "group2", "job3", "group1",
+				new Date(ts), null, 2, 70000L);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() +
+				" will [also] run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		// job4 will run 6 times (run once and repeat 5 more times)
+		// job4 will repeat every 10 seconds (10000 ms)
+		job = new JobDetail("job4", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger4", "group1", "job4", "group1",
+				new Date(ts), null, 5, 10000L);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		// job5 will run once, five minutes past "ts" (300 seconds past "ts")
+		job = new JobDetail("job5", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger5", "group1", "job5", "group1",
+				new Date(ts + 300000L), null, 0, 0);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		// job6 will run indefinitely, every 50 seconds
+		job = new JobDetail("job6", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger6", "group1", "job6", "group1",
+				new Date(ts), null, SimpleTrigger.REPEAT_INDEFINITELY, 50000L);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+
+		log.info("------- Starting Scheduler ----------------");
+
+		// All of the jobs have been added to the scheduler, but none of the jobs
+		// will run until the scheduler has been started
+		sched.start();
+
+		log.info("------- Started Scheduler -----------------");
+
+		// jobs can also be scheduled after start() has been called...
+		// job7 will repeat 20 times, repeat every five minutes
+		job = new JobDetail("job7", "group1", SimpleJob.class);
+		trigger = new SimpleTrigger("trigger7", "group1", "job7", "group1",
+				new Date(ts), null, 20, 300000L);
+		ft = sched.scheduleJob(job, trigger);
+		log.info(job.getFullName() +
+				" will run at: " + ft +  
+				" and repeat: " + trigger.getRepeatCount() + 
+				" times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
+		
+		// jobs can be fired directly... (rather than waiting for a trigger)
+		job = new JobDetail("job8", "group1", SimpleJob.class);
+		job.setDurability(true);
+		sched.addJob(job, true);
+		log.info("'Manually' triggering job8...");
+		sched.triggerJob("job8", "group1");
+
+		log.info("------- Waiting 30 seconds... --------------");
+
+		try {
+			// wait 30 seconds to show jobs
+			Thread.sleep(30L * 1000L); 
+			// executing...
+		} catch (Exception e) {
+		}
+
+		// jobs can be re-scheduled...  
+		// job 7 will run immediately and repeat 10 times for every second
+		log.info("------- Rescheduling... --------------------");
+		trigger = new SimpleTrigger("trigger7", "group1", "job7", "group1", 
+				new Date(), null, 10, 1000L);
+		ft = sched.rescheduleJob("trigger7", "group1", trigger);
+		log.info("job7 rescheduled to run at: " + ft);
+		
+		log.info("------- Waiting five minutes... ------------");
+		try {
+			// wait five minutes to show jobs
+			Thread.sleep(300L * 1000L); 
+			// executing...
+		} catch (Exception e) {
+		}
+
+		log.info("------- Shutting Down ---------------------");
+
+		sched.shutdown(true);
+
+		log.info("------- Shutdown Complete -----------------");
+
+		// display some stats about the schedule that just ran
+		SchedulerMetaData metaData = sched.getMetaData();
+		log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+
+	}
+
+	public static void main(String[] args) throws Exception {
+
+		SimpleTriggerExample example = new SimpleTriggerExample();
+		example.run();
+
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example3/CronTriggerExample.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example3;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * This Example will demonstrate all of the basics of scheduling capabilities of
+ * Quartz using Cron Triggers.
+ * 
+ * @author Bill Kratzer
+ */
+public class CronTriggerExample {
+
+
+	public void run() throws Exception {
+		Log log = LogFactory.getLog(CronTriggerExample.class);
+
+		log.info("------- Initializing -------------------");
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		log.info("------- Initialization Complete --------");
+
+		log.info("------- Scheduling Jobs ----------------");
+
+		// jobs can be scheduled before sched.start() has been called
+
+		// job 1 will run every 20 seconds
+		JobDetail job = new JobDetail("job1", "group1", SimpleJob.class);
+		CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1",
+				"group1", "0/20 * * * * ?");
+		sched.addJob(job, true);
+		Date ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 2 will run every other minute (at 15 seconds past the minute)
+		job = new JobDetail("job2", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger2", "group1", "job2", "group1",
+				"15 0/2 * * * ?");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 3 will run every other minute but only between 8am and 5pm
+		job = new JobDetail("job3", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger3", "group1", "job3", "group1",
+				"0 0/1 8-17 * * ?");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 4 will run every other minute but only between 5pm and 11pm
+		job = new JobDetail("job4", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger4", "group1", "job4", "group1",
+				"0 0/1 17-23 * * ?");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 5 will run at 10am on the 1st and 15th days of the month
+		job = new JobDetail("job5", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger5", "group1", "job5", "group1",
+				"0 0 10am 1,15 * ?");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 6 will run every 30 seconds but only on Weekdays (Monday through
+		// Friday)
+		job = new JobDetail("job6", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger6", "group1", "job6", "group1",
+				"0,30 * * ? * MON-FRI");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		// job 7 will run every 30 seconds but only on Weekends (Saturday and
+		// Sunday)
+		job = new JobDetail("job7", "group1", SimpleJob.class);
+		trigger = new CronTrigger("trigger7", "group1", "job7", "group1",
+				"0,30 * * ? * SAT,SUN");
+		sched.addJob(job, true);
+		ft = sched.scheduleJob(trigger);
+		log.info(job.getFullName() + " has been scheduled to run at: " + ft
+				+ " and repeat based on expression: "
+				+ trigger.getCronExpression());
+
+		log.info("------- Starting Scheduler ----------------");
+
+		// All of the jobs have been added to the scheduler, but none of the
+		// jobs
+		// will run until the scheduler has been started
+		sched.start();
+
+		log.info("------- Started Scheduler -----------------");
+
+		log.info("------- Waiting five minutes... ------------");
+		try {
+			// wait five minutes to show jobs
+			Thread.sleep(300L * 1000L);
+			// executing...
+		} catch (Exception e) {
+		}
+
+		log.info("------- Shutting Down ---------------------");
+
+		sched.shutdown(true);
+
+		log.info("------- Shutdown Complete -----------------");
+
+		SchedulerMetaData metaData = sched.getMetaData();
+		log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+
+	}
+
+	public static void main(String[] args) throws Exception {
+
+		CronTriggerExample example = new CronTriggerExample();
+		example.run();
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example3/SimpleJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example3;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * <p>
+ * This is just a simple job that gets fired off many times by example 1
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class SimpleJob implements Job {
+
+	private static Log _log = LogFactory.getLog(SimpleJob.class);
+
+	/**
+	 * Quartz requires a public empty constructor so that the
+	 * scheduler can instantiate the class whenever it needs.
+	 */
+	public SimpleJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+		_log.info("SimpleJob says: " + jobName + " executing at " + new Date());
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example4/ColorJob.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example4;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.StatefulJob;
+
+/**
+ * <p>
+ * This is just a simple job that receives parameters and
+ * maintains state
+ * </p>
+ * 
+ * @author Bill Kratzer
+ */
+public class ColorJob implements StatefulJob {
+
+	private static Log _log = LogFactory.getLog(ColorJob.class);
+	
+	// parameter names specific to this job
+	public static final String FAVORITE_COLOR = "favorite color";
+	public static final String EXECUTION_COUNT = "count";
+	
+	// Since Quartz will re-instantiate a class every time it
+	// gets executed, members non-static member variables can
+	// not be used to maintain state!
+	private int _counter = 1;
+
+	/**
+	 * <p>
+	 * Empty constructor for job initilization
+	 * </p>
+	 * <p>
+	 * Quartz requires a public empty constructor so that the
+	 * scheduler can instantiate the class whenever it needs.
+	 * </p>
+	 */
+	public ColorJob() {
+	}
+
+	/**
+	 * <p>
+	 * Called by the <code>{@link org.quartz.Scheduler}</code> when a
+	 * <code>{@link org.quartz.Trigger}</code> fires that is associated with
+	 * the <code>Job</code>.
+	 * </p>
+	 * 
+	 * @throws JobExecutionException
+	 *             if there is an exception while executing the job.
+	 */
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+
+		// This job simply prints out its job name and the
+		// date and time that it is running
+		String jobName = context.getJobDetail().getFullName();
+		
+		// Grab and print passed parameters
+		JobDataMap data = context.getJobDetail().getJobDataMap();
+		String favoriteColor = data.getString(FAVORITE_COLOR);
+		int count = data.getInt(EXECUTION_COUNT);
+		_log.info("ColorJob: " + jobName + " executing at " + new Date() + "\n" +
+			"  favorite color is " + favoriteColor + "\n" + 
+			"  execution count (from job map) is " + count + "\n" + 
+			"  execution count (from job member variable) is " + _counter);
+		
+		// increment the count and store it back into the 
+		// job map so that job state can be properly maintained
+		count++;
+		data.put(EXECUTION_COUNT, count);
+		
+		// Increment the local member variable 
+		// This serves no real purpose since job state can not 
+		// be maintained via member variables!
+		_counter++;
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example4/JobStateExample.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example4;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.SimpleTrigger;
+import org.quartz.helpers.TriggerUtils;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * This Example will demonstrate how job parameters can be 
+ * passed into jobs and how state can be maintained
+ * 
+ * @author Bill Kratzer
+ */
+public class JobStateExample {
+
+	public void run() throws Exception {
+		Log log = LogFactory.getLog(JobStateExample.class);
+
+		log.info("------- Initializing -------------------");
+
+		// First we must get a reference to a scheduler
+		SchedulerFactory sf = new StdSchedulerFactory();
+		Scheduler sched = sf.getScheduler();
+
+		log.info("------- Initialization Complete --------");
+
+		log.info("------- Scheduling Jobs ----------------");
+
+		// get a "nice round" time a few seconds in the future....
+		long ts = TriggerUtils.getNextGivenSecondDate(null, 10).getTime();
+
+		// job1 will only run 5 times, every 10 seconds
+		JobDetail job1 = new JobDetail("job1", "group1", ColorJob.class);
+		SimpleTrigger trigger1 = new SimpleTrigger("trigger1", "group1", "job1", "group1",
+				new Date(ts), null, 4, 10000);
+		// pass initialization parameters into the job
+		job1.getJobDataMap().put(ColorJob.FAVORITE_COLOR, "Green");
+		job1.getJobDataMap().put(ColorJob.EXECUTION_COUNT, 1);
+		
+		// schedule the job to run
+		Date scheduleTime1 = sched.scheduleJob(job1, trigger1);
+		log.info(job1.getFullName() +
+				" will run at: " + scheduleTime1 +  
+				" and repeat: " + trigger1.getRepeatCount() + 
+				" times, every " + trigger1.getRepeatInterval() / 1000 + " seconds");
+
+		// job2 will also run 5 times, every 10 seconds
+		JobDetail job2 = new JobDetail("job2", "group1", ColorJob.class);
+		SimpleTrigger trigger2 = new SimpleTrigger("trigger2", "group1", "job2", "group1",
+				new Date(ts + 1000), null, 4, 10000);
+		// pass initialization parameters into the job
+		// this job has a different favorite color!
+		job2.getJobDataMap().put(ColorJob.FAVORITE_COLOR, "Red");
+		job2.getJobDataMap().put(ColorJob.EXECUTION_COUNT, 1);
+		
+		// schedule the job to run
+		Date scheduleTime2 = sched.scheduleJob(job2, trigger2);
+		log.info(job1.getFullName() +
+				" will run at: " + scheduleTime1 +  
+				" and repeat: " + trigger1.getRepeatCount() + 
+				" times, every " + trigger1.getRepeatInterval() / 1000 + " seconds");
+
+
+
+		log.info("------- Starting Scheduler ----------------");
+
+		// All of the jobs have been added to the scheduler, but none of the jobs
+		// will run until the scheduler has been started
+		sched.start();
+
+		log.info("------- Started Scheduler -----------------");
+		
+		log.info("------- Waiting 60 seconds... -------------");
+		try {
+			// wait five minutes to show jobs
+			Thread.sleep(60L * 1000L); 
+			// executing...
+		} catch (Exception e) {
+		}
+
+		log.info("------- Shutting Down ---------------------");
+
+		sched.shutdown(true);
+
+		log.info("------- Shutdown Complete -----------------");
+
+		SchedulerMetaData metaData = sched.getMetaData();
+		log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
+
+	}
+
+	public static void main(String[] args) throws Exception {
+
+		JobStateExample example = new JobStateExample();
+		example.run();
+	}
+
+}

File quartz_1x/src/java/examples/org/quartz/examples/example5/MisfireExample.java

+/*
+ * Copyright (c) 2005 by OpenSymphony
+ * All rights reserved.
+ * 
+ */
+package org.quartz.examples.example5;
+
+import java.util.Date;
+
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerFactory;
+import org.quartz.SchedulerMetaData;
+import org.quartz.SimpleTrigger;
+import org.quartz.examples.StatefulDumbJob;
+import org.quartz.helpers.TriggerUtils;
+import org.quartz.impl.StdSchedulerFactory;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * Demonstrates the behavior of <code>StatefulJob</code>s, as well as how
+ * misfire instructions affect the firings of triggers of <code>StatefulJob</code>
+ * s - when the jobs take longer to execute that the frequency of the trigger's
+ * repitition.
+ * 
+ * <p>
+ * While the example is running, you should note that there are two triggers
+ * with identical schedules, firing identical jobs. The triggers "want" to fire
+ * every 3 seconds, but the jobs take 10 seconds to execute. Therefore, by the
+ * time the jobs complete their execution, the triggers have already "misfired"
+ * (unless the scheduler's "misfire threshold" has been set to more than 7
+ * seconds). You should see that one of the jobs has its misfire instruction
+ * set to <code>SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT</code>,
+ * which causes it to fire immediately, when the misfire is detected. The other
+ * trigger uses the default "smart policy" misfire instruction, which causes
+ * the trigger to advance to its next fire time (skipping those that it has
+ * missed) - so that it does not refire immediately, but rather at the next
+ * scheduled time.
+ * </p>
+ *