Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Implementing more than one Job Details and Triggers 
 

In this quartz tutorial, we will learn how to implement more than one triggers and jobs with a quartz scheduler.

 

Implementing more than one Job Details and Triggers

                         

In this quartz tutorial, we will learn how to implement more than one triggers and jobs with a quartz scheduler. We know that the scheduler is a main interface of quartz scheduler that contains Job Details and Triggers. It has a name and group associated with them and it can be identified by the single scheduler. See below for an implementation of more than one job details and triggers.

Description of program:

Here, we are going to implement more than one job details and triggers with the help of following program that jobs name, triggers name and its firing date and time. We have known about the quartz application, when we wish to implement any quartz application then we will require two classes: one is Scheduler class (MoreTriggerSchedule.java) and another is Job class (MoreTriggerJob.java) that will implement in the Job interface. In this program, the Job class will represent the job's name, trigger's name and its firing times with day and date as well as GMT format time. The scheduler class is a main class of this quartz application that implements the Scheduler instance. But, when we will go to implement this instance then we need an object of the SchedulerFactory invoked by the getScheduler() method. Now, we start the scheduler by using the start() method. The quartz Scheduler has JobDetail and CronTrigger objects. These are attached in the quartz by the scheduleJob() method. After completing the entire processes then we will get all jobs and triggers to be used in it.

Description of code:

(0/5   *  *   *   *   ?): This corn expression provides the facility for firing the trigger every 5 seconds to un-limit time.

(0/8   *   *   *   *   ?): This expression allows to the trigger for firing every 8 seconds to infinite time.

Here is the code of Scheduler class (MoreTriggerSchedule.java):

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;


public class MoreTriggerSchedule {
  public static void main(String args[]){
    try{
      new MoreTriggerSchedule();
    }catch(Exception e){
      e.printStackTrace();
    }
  }
  public MoreTriggerSchedule()throws Exception{
    JobDetail jDetail;
    CronTrigger cronTrigger;
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sche = sf.getScheduler();
         sche.start();
    jDetail = new JobDetail("Job1","group1",MoreTriggerJob.class);
    cronTrigger = new CronTrigger("cronTrigger1","group1","0/5 * * * * ?");
    sche.scheduleJob(jDetail, cronTrigger);
    jDetail = new JobDetail("Job2","group2",MoreTriggerJob.class);
    cronTrigger = new CronTrigger("cronTrigger2","group2","0/8 * * * * ?");
    sche.scheduleJob(jDetail, cronTrigger);
    
  }
}

 Download this example.

Here is the code of Job class (MoreTriggerJob.java):

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;


public class MoreTriggerJob implements Job {

  public void execute(JobExecutionContext contextthrows JobExecutionException {
    // TODO Auto-generated method stub
    System.out.println("Job name: " + context.getJobDetail().getName());
    System.out.println("Trigger name: " + context.getTrigger().getName());
    System.out.println("Firing Time: " + context.getFireTime());
  }

}

 Download this example.

Output of program:

log4j:WARN No appenders could be found for logger (org.quartz.simpl.SimpleThreadPool).

log4j:WARN Please initialize the log4j system properly.

Job name: Job2

Trigger name: cronTrigger2

Firing Time: Tue Feb 27 10:06:56 GMT+05:30 2007

Job name: Job1

Trigger name: cronTrigger1

Firing Time: Tue Feb 27 10:07:00 GMT+05:30 2007

Job name: Job2

Trigger name: cronTrigger2

Firing Time: Tue Feb 27 10:07:00 GMT+05:30 2007

                         

» View all related tutorials
Related Tags: c ide list interface script object io ip vi factory trigger instance int this id ai job shutdown if example

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.