标签:
通过定时任务调度框架Quartz可以实现某些定时功能,定时执行某些方法等功能。下面提供一个简单的例子,实现Quartz框架的Hello World.
import org.quartz.CronExpression; import org.quartz.CronTrigger; import org.quartz.Job; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; import org.quartz.impl.StdSchedulerFactory; public class DiaoduTest implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println(new Date() + "天佑最帅!!!"); } public static void main(String[] args) { JobDetail detail = new JobDetail("job1", "group1", DiaoduTest.class); CronTrigger cronTrigger = new CronTrigger("job1", "group1"); try { CronExpression cronExpression = new CronExpression("0/1 * * * * ?"); cronTrigger.setCronExpression(cronExpression); SchedulerFactory factory = new StdSchedulerFactory(); Scheduler scheduler; try { scheduler = factory.getScheduler(); try { scheduler.scheduleJob(detail, cronTrigger); scheduler.start(); } catch (SchedulerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (SchedulerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:
原文地址:http://www.cnblogs.com/qiutianyou/p/5513167.html