我正在尝试在Quartz 1.6中创建Job
,但是只需要执行一次,因为我有两个具有相同版本的.war文件的测试实例。p>这是我的TestPlugin
类,Job
将每60秒执行一次:
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();
}
}
}
然后我有我的类TestExecute
来打印一个简单的输出:
@DisallowConcurrentExecution
public class TestDemonio implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("QUARTZ JOB MESSAGE");
}
}
我已经研究了如何通过添加注释@DisallowConcurrentExecution
来实现我想要的目标,仅执行工作后,但是我收到了每个实例上打印的消息。
这是我的Quartz.properties文件:
# 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
您需要将以下属性添加到Quartz.property文件(来源:单击此处(:
org.quartz.jobStore.isClustered : true
阅读此信息以获取有关isClustered
属性的更多信息,请参阅此链接。
请注意:
@dislowalconcurrentexecution有2个不同的作业,在同一节点上运行同一JobKey时,有效。
虽然使用isclustered属性来确保在应用程序通过数据库表传达的多个节点以获取原子能。