Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Tutorials
  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. 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

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.