Wednesday, September 24, 2008

Quartz - For Scheduling

Quartz is a full-featured, open source job scheduling system that can be integrated with,or used along side virtually any J2EE or J2SE application.It can mainly be used for Driving WrkFlow and System maintainance.
It can be integrated with any system with ease.It can perform simple or complicated schedules based on given cron expression.The execution logic can be embedded into simple java classes by implementing certain intefaces.
The job information can either be stored in memory through RAMJobStore or can be stored in relational databases using JDBCJobStore.If RAMJobStore is used whenever the server restarts, previously scheduled data is lost.
For scheduling jobs a scheduler needs to be started and jobs can be added as shown below.
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
JobDetail jobDetail = new JobDetail("myJob", null, DumbJob.class);
Trigger trigger = TriggerUtils.makeHourlyTrigger(); // fire every hour trigger.setStartTime(TriggerUtils.getEvenHourDate(new Date())); // start on the next even hour trigger.setName("myTrigger");
sched.scheduleJob(jobDetail, trigger);
Custom job should implement the following interface
Job Interfacepackage org.quartz;
public interface Job {
public void execute(JobExecutionContext context) throws JobExecutionException; }
CronTrigger needs to be used for more complicated schedules.
An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm".

No comments:

 
Free Domain Names @ .co.nr!