Quartz Scheduler Example Programs and Sample Code : Quartz Code Snippets : How-To: Define a Job (with input data)
How-To: Define a Job (with input data)
A Job Class
public class PrintPropsJob implements Job {
public PrintPropsJob() {
// Instances of Job must have a public no-argument constructor.
}
public void execute(JobExecutionContext context)
throws JobExecutionException {
JobDataMap data = context.getMergedJobDataMap();
System.out.println("someProp = " + data.getString("someProp"));
}
}
Defining a Job Instance
// Define job instance
JobDetail job1 = newJob(MyJobClass.class)
.withIdentity("job1", "group1")
.usingJobData("someProp", "someValue")
.build();
Note that if your Job class contains setter methods that match your JobDataMap keys (for example. "setSomeProp" in the example above), and you use the default JobFactory implementation, Quartz will automatically call the setter method with the JobDataMap value. Thus, there is no need to include code in the Job's execute method to retrieve the value from the JobDataMap.
Copyright © 2010-2016 Software AG, Darmstadt, Germany.

Product Logo |   Feedback