According to Quratz documentation2.x Here
If you add setter methods to your job class that correspond to the names of keys in the JobDataMap (such as a setJobSays(String val) method for the data in the example above), then Quartz’s default JobFactory implementation will automatically call those setters when the job is instantiated, thus preventing the need to explicitly get the values out of the map within your execute method.
Now in my case the setters are not automatically called although my all values are primitives. Also in execute method i am able to get values from jobDataMap. i am using Quartz 2.2.1 and here is my sample code.what should i do ? thanks in advance.
Here is my Job class.
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class Db2Db implements Job {
public static final String SOURCE_HOST = "sourceHost";
public static final String DESTINATION_HOST = "destinationHost";
protected String sourceHost;
protected String destinationHost;
public Db2Db() {
System.out.println("created object of job");
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
//sourceHost is still null
system.out.println(sourceHost);
}
public void setSourceHost(String sourceHost) {
this.sourceHost = sourceHost;
}
public void setDestinationHost(String destinationHost) {
this.destinationHost= destinationHost;
}
}
and Here is my main method
public class JobDriver {
public static void main(String[] args) throws SchedulerException {
/*Starting quartz server remotely*/
QuartzServer server = QuartzServer.getInstance();
server.start();
JobDetail job = newJob(Db2Db.class)
.usingJobData(SOURCE_HOST, "132.168.0.12")
.usingJobData(DESTINATION_HOST, "localhost")
.withIdentity("DailyRead91", "group1")
.build();
Trigger trigger = newTrigger().withIdentity("DailyTrigger91", "group1").startNow()
.withSchedule(simpleSchedule().withIntervalInSeconds(10).repeatForever()).build();
//Quartz Server Properties
Properties prop = new Properties();
prop.put("org.quartz.scheduler.rmi.proxy", "true");
prop.put("org.quartz.scheduler.rmi.registryHost", "localhost");
prop.put("org.quartz.scheduler.rmi.registryPort", "1099");
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
prop.put("org.quartz.threadPool.threadCount", "10");
Scheduler scheduler = new StdSchedulerFactory(prop).getScheduler();
scheduler.scheduleJob(job, trigger);
}
}