From 459b5dcfb596f1b6520ab1c8ca70fcd15928b9b9 Mon Sep 17 00:00:00 2001 From: DengMin <16679070171@qq.com> Date: Sat, 2 Apr 2022 12:29:21 +0800 Subject: [PATCH] 定时器位数计算不足问题修复 --- src/main/java/com/subsidy/util/QuartzUtil.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/subsidy/util/QuartzUtil.java b/src/main/java/com/subsidy/util/QuartzUtil.java index d60aeca..2ec3f5e 100644 --- a/src/main/java/com/subsidy/util/QuartzUtil.java +++ b/src/main/java/com/subsidy/util/QuartzUtil.java @@ -27,6 +27,10 @@ public class QuartzUtil { @Autowired private Scheduler scheduler; + public static void main(String[] args) { + System.out.println(DateFormatUtil.parse("2022-06-28 11:30:47", "yyyy-MM-dd HH:mm:ss").getTime() -System.currentTimeMillis()); + } + /** * 添加定时任务,只执行一次的定时任务 * @@ -41,7 +45,7 @@ public class QuartzUtil { JobKey key = new JobKey(name, group); List triggers = (List) scheduler.getTriggersOfJob(key); if (triggers.size() == 0) { - int time = (int) (date.getTime() - System.currentTimeMillis()) / 1000; + Long time = (date.getTime() - System.currentTimeMillis()) / 1000; JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("params", params); JobDetail jobDetail = JobBuilder.newJob(cls) @@ -50,7 +54,7 @@ public class QuartzUtil { .build(); SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger() .withIdentity(name, group) - .startAt(futureDate(time, DateBuilder.IntervalUnit.SECOND)) + .startAt(futureDate(Math.toIntExact(time), DateBuilder.IntervalUnit.SECOND)) .build(); scheduler.scheduleJob(jobDetail, trigger); if (!scheduler.isShutdown()) { -- libgit2 0.25.0