//任务类
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    import org.springframework.stereotype.Service;
    
    @Service
    public class MyJob implements Job {
    
        @Override
      public void execute(JobExecutionContext context) throws JobExecutionException {
            System.out.println("我的任务" + context.getTrigger().getJobKey().toString());
    
      }
    }
    
    
    //动态启动定时工具类
    import com.centit.hnicimp.modules.warning.po.WarningRule;
    import com.centit.hnicimp.modules.warning.service.MyJob;
    import org.quartz.*;
    import org.quartz.impl.StdSchedulerFactory;
    import org.springframework.stereotype.Service;
    
    /**
     * 动态启动定时工具类
      *
     * @author zk
     */@Service
    public class JobUtils {
    
        //创建定时任务
      public static void startTask(WarningRule warningRule) {
            //传入参数为  任务key
      JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity(warningRule.getVcId()).build();
      //传入参数为   VcId业务id  RuleName业务名称  RuleExcPc定时Cron表达式
      CronTrigger trigger = (CronTrigger) TriggerBuilder.newTrigger()
                .withIdentity(warningRule.getVcId(), warningRule.getRuleName())
                .withSchedule(CronScheduleBuilder.cronSchedule(warningRule.getRuleExcPc())).build();
      SchedulerFactory schedulerFactory = new StdSchedulerFactory();
      Scheduler scheduler = null;
     try {
                scheduler = schedulerFactory.getScheduler();
      scheduler.start();
      scheduler.scheduleJob(jobDetail, trigger);
      } catch (SchedulerException e) {
                e.printStackTrace();
      System.out.println("定时任务发生异常");
      }
        }
    
        //删除定时任务
      public static void deleteTask(WarningRule warningRule) {
            //传入参数为  任务key
      JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity(warningRule.getVcId()).build();
      SchedulerFactory schedulerFactory = new StdSchedulerFactory();
      Scheduler scheduler = null;
     try {
                scheduler = schedulerFactory.getScheduler();
      scheduler.deleteJob(jobDetail.getKey());
      } catch (SchedulerException e) {
                e.printStackTrace();
      System.out.println("定时任务发生异常");
      }
    
        }
    }