// 开启一个定时任务,如果两天后用户没有手动关闭这次咨询,则自动关闭 JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("consultingId", consultingId); jobDataMap.put("consultationService", consultationService); JobDetail detail = JobBuilder.newJob(ManualCancelConsultationTask.class) .withIdentity("job-" + consultingId, "group-" + consultingId) .usingJobData(jobDataMap) .build(); Trigger trigger = TriggerBuilder.newTrigger() .forJob(detail) .withSchedule( SimpleScheduleBuilder .simpleSchedule() .withIntervalInSeconds(10) .withRepeatCount(1) ).build(); scheduler.scheduleJob(detail, trigger); scheduler.start();
代码如上,我想让定时任务只执行一次,10秒后执行。但scheduler.start()后执行了一次,10秒后又执行了一次。