定时任务写法
SchedulerFactory schedulerFactory = new StdSchedulerFactory(); try { Scheduler scheduler = schedulerFactory.getScheduler(); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("warning", this); JobDetail onlineJobDetail = JobBuilder.newJob(OnlineUserWarningJobDetail.class) .usingJobData(jobDataMap) .withIdentity("onlineJob", "onelineJobGroup") .build(); Trigger oldtrigger = scheduler.getTrigger(TriggerKey.triggerKey("onlineTrigger", "onlineTriggerGroup")); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("onlineTrigger", "onlineTriggerGroup") .startNow() .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(time).repeatForever()) .build(); if(null != oldtrigger) { scheduler.rescheduleJob(TriggerKey.triggerKey("onlineTrigger", "onlineTriggerGroup"), trigger); }else { scheduler.scheduleJob(onlineJobDetail, trigger); //启动定时任务 scheduler.start(); } } catch (SchedulerException e) { e.printStackTrace(); }