I'm trying to create a Job
in Quartz 1.6, but with the necessity to execute only once, because I have two test instances with the same version of a .war file.
This is my TestPlugin
class, the Job
will be executed every 60 seconds:
public class TestPlugin implements PlugIn {
public TestPlugin() {
super();
}
public void destroy() {
}
public void init(ActionServlet arg0, ModuleConfig arg1)
throws ServletException {
try {
JobDetail job = JobBuilder.newJob(TestDemonio.class)
.withIdentity("anyJobName", "group1").build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("anyTriggerName", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0/60 * * ? * * *"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
Then I have my class TestExecute
to print a simple output:
@DisallowConcurrentExecution
public class TestDemonio implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("QUARTZ JOB MESSAGE");
}
}
I have researched on how to achieve what I want by adding the annotation @DisallowConcurrentExecution
, to only execute once the job, but I receive a message printed on each instance.
This is my quartz.properties file:
# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 10
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
org.quartz.jobStore.misfireThreshold: 60000
org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore