What is Quartz?
Quartz is a full-featured, open source job scheduling framework. Quartz can be used to create simple or complex schedulers for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do.
The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.
Demo:
Scheduler: This a Scheduler Program, that schedules or Triggers a Job(Java Program) on a specified frequency.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package demoquartz;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
/**
*
* @author sathya
*/
public class DemoScheduler {
public static void main (String[] args) {
try {
SchedulerFactory factory = new org.quartz.impl.StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
scheduler.start();
JobDetail jobDetail = new JobDetail("demmoJob", null, DemoJob.class);
// Fires every 10 seconds
Trigger ranchTrigger = TriggerUtils.makeSecondlyTrigger(10);
ranchTrigger.setName("ranchTrigger");
scheduler.scheduleJob(jobDetail, ranchTrigger);
} catch (SchedulerException ex) {
ex.printStackTrace();
}
}
}
Job : Job to be Triggered by the Scheduler
package demoquartz;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
*
* @author sathya
*/
public class DemoJob implements Job {
public void execute (JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Welcome at Quartz Scheduled Job....");
}
}
Libraries required : commons-logging.jar and quartz.-1.6.6.jar
Thanks
Sathya
Sathya
No comments:
Post a Comment