From 19d1ac2ec2704109b346067ab3cb1e3d9de2bb24 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Wed, 22 May 2019 17:04:47 +0800 Subject: [PATCH] update document --- .../admin/core/thread/JobScheduleHelper.java | 4 +-- .../admin/service/impl/XxlJobServiceImpl.java | 29 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java index 26f9452a..75ebcbd7 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobScheduleHelper.java @@ -58,8 +58,8 @@ public class JobScheduleHelper { // tx start - // 1、查询JOB:"下次调度30s内" - long maxNextTime = System.currentTimeMillis() + 30000; + // 1、预读10s内调度任务 + long maxNextTime = System.currentTimeMillis() + 10000; long nowTime = System.currentTimeMillis(); List scheduleList = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleJobQuery(maxNextTime); if (scheduleList!=null && scheduleList.size()>0) { diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java index ba40bd8d..d80ac566 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java @@ -189,13 +189,15 @@ public class XxlJobServiceImpl implements XxlJobService { return new ReturnT(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) ); } - // next trigger time + // next trigger time (10s后生效,避开预读周期) long nextTriggerTime = 0; - try { - nextTriggerTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date()).getTime(); - } catch (ParseException e) { - logger.error(e.getMessage(), e); - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); + if (exists_jobInfo.getTriggerStatus() == 1) { + try { + nextTriggerTime = new CronExpression(jobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + 10000)).getTime(); + } catch (ParseException e) { + logger.error(e.getMessage(), e); + return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); + } } exists_jobInfo.setJobGroup(jobInfo.getJobGroup()); @@ -234,10 +236,10 @@ public class XxlJobServiceImpl implements XxlJobService { public ReturnT start(int id) { XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); - // next trigger time + // next trigger time (10s后生效,避开预读周期) long nextTriggerTime = 0; try { - nextTriggerTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date()).getTime(); + nextTriggerTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date(System.currentTimeMillis() + 10000)).getTime(); } catch (ParseException e) { logger.error(e.getMessage(), e); return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); @@ -255,18 +257,9 @@ public class XxlJobServiceImpl implements XxlJobService { public ReturnT stop(int id) { XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id); - // next trigger time - long nextTriggerTime = 0; - try { - nextTriggerTime = new CronExpression(xxlJobInfo.getJobCron()).getNextValidTimeAfter(new Date()).getTime(); - } catch (ParseException e) { - logger.error(e.getMessage(), e); - return new ReturnT(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid")+" | "+ e.getMessage()); - } - xxlJobInfo.setTriggerStatus(0); xxlJobInfo.setTriggerLastTime(0); - xxlJobInfo.setTriggerNextTime(nextTriggerTime); + xxlJobInfo.setTriggerNextTime(0); xxlJobInfoDao.update(xxlJobInfo); return ReturnT.SUCCESS;