Quartz Scheduler Example Programs and Sample Code : Quartz Code Snippets : How-To: Use Job Listeners
How-To: Use Job Listeners
Creating a JobListener
Implement the JobListener interface.
package foo;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
public class MyJobListener implements JobListener {
private String name;
public MyJobListener(String name) {
this.name = name;
}

public String getName() {
return name;
}
public void jobToBeExecuted(JobExecutionContext context) {
// do something with the event
}
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
// do something with the event
}
public void jobExecutionVetoed(JobExecutionContext context) {
// do something with the event
}
}
- OR -
Extend JobListenerSupport.
package foo;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.listeners.JobListenerSupport;
public class MyOtherJobListener extends JobListenerSupport {
private String name;

public MyOtherJobListener(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
// do something with the event
}
}
Registering a JobListener with the Scheduler to Listen to All Jobs
scheduler.getListenerManager().addJobListener(myJobListener,
   allJobs());
Registering a JobListener with the Scheduler to Listen to A Specific Job
scheduler.getListenerManager().addJobListener(myJobListener,
   jobKeyEquals(jobKey("myJobName", "myJobGroup")));
Registering a JobListener with the Scheduler to Listen to all Jobs in a Group
scheduler.getListenerManager().addJobListener(myJobListener,
   jobGroupEquals("myJobGroup"));
Copyright © 2010-2016 Software AG, Darmstadt, Germany.

Product Logo |   Feedback