SchedulerService { public void editCronJob(TaskInfo info) { String jobName = info.getJobName(); String jobGroupName = info.getJobGroupName(); String jobDescription = info.getJobDescription(); String cronExpression = info.getCronExpression(); JobDataMap dataMap = new JobDataMap(); if (info.getData() != null) { dataMap.putAll(info.getData()); } try { if (!checkExists(jobName, jobGroupName)) { throw new OpenAlertException( String.format("Job不存在, jobName:{%s},jobGroup:{%s}", jobName, jobGroupName)); } TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroupName); JobKey jobKey = new JobKey(jobName, jobGroupName); CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder .cronSchedule(cronExpression) .withMisfireHandlingInstructionDoNothing(); CronTrigger cronTrigger = TriggerBuilder.newTrigger() .withIdentity(triggerKey) .withSchedule(cronScheduleBuilder).build(); JobDetail jobDetail = scheduler.getJobDetail(jobKey); jobDetail = jobDetail.getJobBuilder().withDescription(jobDescription).usingJobData(dataMap).build(); HashSet<Trigger> triggerSet = new HashSet<>(); triggerSet.add(cronTrigger); scheduler.scheduleJob(jobDetail, triggerSet, true); } catch (SchedulerException e) { throw new OpenAlertException("类名不存在或执行表达式错误"); } }  List<String> getJobGroupNames(); List<TaskInfo> getJobList(); void addSimpleJob(TaskInfo info); void addCronJob(TaskInfo info); void editSimpleJob(TaskInfo info); void editCronJob(TaskInfo info); void deleteJob(String jobName, String jobGroup); void pauseJob(String jobName, String jobGroup); void resumeJob(String jobName, String jobGroup);  }
@Test public void editJob() { String cron = "3 * * * * ? *"; TaskInfo taskInfo = new TaskInfo(); Map data = Maps.newHashMap(); String serviceId = "upm-server"; data.put("serviceId", serviceId); data.put("method", "get"); data.put("path", "/test"); data.put("contentType", "application/x-www-form-urlencoded"); data.put("alarmMail", "515608851@qq.com"); taskInfo.setData(data); taskInfo.setJobName("定时任务测试"); taskInfo.setJobDescription("定时任务描述3秒2222222执行一次"); taskInfo.setJobClassName(HttpExecuteJob.class.getName()); taskInfo.setJobGroupName(Scheduler.DEFAULT_GROUP); taskInfo.setCronExpression(cron); schedulerService.editCronJob(taskInfo); }