From 51bfaa4131ec239c438daaaff3964024716b9f76 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Mon, 11 Jan 2016 19:18:30 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=B0=83=E5=BA=A6=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=8F=96=E6=B6=88=E8=A1=A5=E5=81=BF=E9=81=97?= =?UTF-8?q?=E5=A4=B1=E8=B0=83=E5=BA=A6=EF=BC=9B=202=E3=80=81=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E5=90=AF=E5=8A=A8=E8=B0=83=E5=BA=A6=E5=99=A8=EF=BC=9B?= =?UTF-8?q?=203=E3=80=81=E6=94=AF=E6=8C=81=E8=B0=83=E5=BA=A6=E9=9D=9E?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E6=89=A7=E8=A1=8C=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=EF=BC=88=E9=9C=80=E8=A6=81=E6=89=A9=E5=A4=A7?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=95=B0=EF=BC=89=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/core/util/DynamicSchedulerUtil.java | 6 +++--- .../main/resources/applicationcontext-trigger-db.xml | 3 ++- .../main/java/com/xxl/job/service/job/DemoJobBean.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java index 75c3f4d9..fdd1f6a4 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/core/util/DynamicSchedulerUtil.java @@ -104,8 +104,8 @@ public final class DynamicSchedulerUtil implements InitializingBean { return false; } - // CronTrigger : TriggerKey + cronExpression - CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + // CronTrigger : TriggerKey + cronExpression // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度 + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); // JobDetail : jobClass @@ -131,7 +131,7 @@ public final class DynamicSchedulerUtil implements InitializingBean { boolean result = false; if (scheduler.checkExists(triggerKey)) { // CronTrigger : TriggerKey + cronExpression - CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); Date date = scheduler.rescheduleJob(triggerKey, cronTrigger); diff --git a/xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml b/xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml index 58e268f7..edc52237 100644 --- a/xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml +++ b/xxl-job-admin/src/main/resources/applicationcontext-trigger-db.xml @@ -11,7 +11,8 @@ - + + diff --git a/xxl-job-simple/src/main/java/com/xxl/job/service/job/DemoJobBean.java b/xxl-job-simple/src/main/java/com/xxl/job/service/job/DemoJobBean.java index 5345578a..77aa8a2a 100644 --- a/xxl-job-simple/src/main/java/com/xxl/job/service/job/DemoJobBean.java +++ b/xxl-job-simple/src/main/java/com/xxl/job/service/job/DemoJobBean.java @@ -3,7 +3,9 @@ package com.xxl.job.service.job; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; +import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.slf4j.Logger; @@ -14,6 +16,8 @@ import org.springframework.scheduling.quartz.QuartzJobBean; * http job bean * @author xuxueli 2015-12-17 18:20:34 */ + +@DisallowConcurrentExecution // 取消并发执行;线程数要多配置几个,否则不生效; public class DemoJobBean extends QuartzJobBean { private static Logger logger = LoggerFactory.getLogger(DemoJobBean.class); @@ -33,6 +37,12 @@ public class DemoJobBean extends QuartzJobBean { } } + try { + TimeUnit.SECONDS.sleep(5); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info(">>>>>>>>>>> xxl-job run :jobId:{}, group:{}, jobDataMap:{}", new Object[]{triggerKey, triggerGroup, jobDataMap}); }