quartz 实例

public class RmcHeartScheduler implements Runnable {
 static Logger log = Log4jManage.getLog();
 
 private void heartScheduler ()
 {
  SchedulerFactory schedFact = new StdSchedulerFactory();
  try {
   log.info("start HeartScheduler");
   //获取调度器
   Scheduler sched = schedFact.getScheduler();
   //启动调度器
   sched.start();
   //向调度器注册一个任务
   JobDetail heartMail = new JobDetail("heartmailjob", null,
     RmcHeartMail.class);
   sched.addJob(heartMail, true);
   //创建一个每72小时触发一次的触发器
   Trigger trigger = TriggerUtils.makeHourlyTrigger(12);
   //设置触发器的名字
   trigger.setName("heartmail");
   //设置触发器关联的任务
   trigger.setJobName(heartMail.getName());
   Thread.sleep(12 * 3600 * 1000);
   //向调度器注册触发器
   sched.scheduleJob(trigger);
   
  } catch (SchedulerException e) {
   log.error("heart mail SchedulerException");
   log.error(e.getMessage());
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   log.error(e.getMessage());
  }
 }

 @Override
 public void run() {
  // TODO Auto-generated method stub
  heartScheduler();
 }

}

 

 

 

 

public class RmcHeartMail implements Job {
 @Override
 public void execute(JobExecutionContext arg0) throws JobExecutionException {
  System.out.println("start");
 }
 
}

你可能感兴趣的:(quartz)