quartz的trigger时间是“每秒执行一次”,
QuartzManager.addJob(jobName, job, "0/1 * * * * ?");
job的执行时间是“每次执行30秒”
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { System.out.println(value + "_" + Thread.currentThread().getName() + "__" + hashCode() + ",执行时间:" + new Date()); try { //模拟执行30秒 Thread.sleep(30L * 1000); } catch (InterruptedException e) { e.printStackTrace(); } }
quartz的配置,线程池中只有一个线程:
org.quartz.threadPool.threadCount = 1
实际测试结果:
【系统启动】 2013-1-25 9:25:55 org.quartz.simpl.SimpleThreadPool initialize 信息: Job execution threads will use class loader of thread: main 2013-1-25 9:25:55 org.quartz.core.QuartzScheduler <init> 信息: Quartz Scheduler v.1.5.2 created. 2013-1-25 9:25:55 org.quartz.simpl.RAMJobStore initialize 信息: RAMJobStore initialized. 2013-1-25 9:25:55 org.quartz.impl.StdSchedulerFactory instantiate 信息: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' 2013-1-25 9:25:55 org.quartz.impl.StdSchedulerFactory instantiate 信息: Quartz scheduler version: 1.5.2 2013-1-25 9:25:55 org.quartz.core.QuartzScheduler start 信息: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. aaaa_DefaultQuartzScheduler_Worker-0__821556544,执行时间:Fri Jan 25 09:25:55 CST 2013 aaaa_DefaultQuartzScheduler_Worker-0__1139773783,执行时间:Fri Jan 25 09:26:25 CST 2013
并没有每秒都执行,而是每30秒执行一次。
经验:
1.“调度”应该和“执行”分开,中间附加“消息队列”