Commit 459b5dcf by 邓敏

定时器位数计算不足问题修复

1 parent c4adc855
...@@ -27,6 +27,10 @@ public class QuartzUtil { ...@@ -27,6 +27,10 @@ public class QuartzUtil {
@Autowired @Autowired
private Scheduler scheduler; 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 { ...@@ -41,7 +45,7 @@ public class QuartzUtil {
JobKey key = new JobKey(name, group); JobKey key = new JobKey(name, group);
List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(key); List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(key);
if (triggers.size() == 0) { if (triggers.size() == 0) {
int time = (int) (date.getTime() - System.currentTimeMillis()) / 1000; Long time = (date.getTime() - System.currentTimeMillis()) / 1000;
JobDataMap jobDataMap = new JobDataMap(); JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("params", params); jobDataMap.put("params", params);
JobDetail jobDetail = JobBuilder.newJob(cls) JobDetail jobDetail = JobBuilder.newJob(cls)
...@@ -50,7 +54,7 @@ public class QuartzUtil { ...@@ -50,7 +54,7 @@ public class QuartzUtil {
.build(); .build();
SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger() SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger()
.withIdentity(name, group) .withIdentity(name, group)
.startAt(futureDate(time, DateBuilder.IntervalUnit.SECOND)) .startAt(futureDate(Math.toIntExact(time), DateBuilder.IntervalUnit.SECOND))
.build(); .build();
scheduler.scheduleJob(jobDetail, trigger); scheduler.scheduleJob(jobDetail, trigger);
if (!scheduler.isShutdown()) { if (!scheduler.isShutdown()) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!