加入Quartz

把下列的jar放入WebContent/WEB-INF/lib下

  • quartz-2.2.1.jar
  • nutz-integration-quartz-1.r.60.r2.jar

在conf目录下,新建一个文件叫quartz.properties,内容如下

  1. org.quartz.scheduler.instanceName = NutzbookScheduler
  2. org.quartz.threadPool.threadCount = 3
  3. org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
  4. org.quartz.scheduler.skipUpdateCheck=true

打开MainModule,修改IocBy为

  1. @IocBy(type=ComboIocProvider.class, args={
  2. "*js", "ioc/",
  3. "*anno", "net.wendal.nutzbook",
  4. "*tx",
  5. "*quartz"})

即添加了 org.nutz.integration.quartz.QuartzIocLoader 这个预定义的集成配置

打开MainSetup类, 在init方法末尾,添加代码

  1. // 获取NutQuartzCronJobFactory从而触发计划任务的初始化与启动
  2. ioc.get(NutQuartzCronJobFactory.class);

仔细检查后,启动tomcat, 应有如下log输出

  1. 2015-04-24 23:07:34,706 org.quartz.core.SchedulerSignalerImpl.<init>(SchedulerSignalerImpl.java:61) INFO - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
  2. 2015-04-24 23:07:34,706 org.quartz.core.QuartzScheduler.<init>(QuartzScheduler.java:240) INFO - Quartz Scheduler v.2.2.1 created.
  3. 2015-04-24 23:07:34,707 org.quartz.simpl.RAMJobStore.initialize(RAMJobStore.java:155) INFO - RAMJobStore initialized.
  4. 2015-04-24 23:07:34,707 org.quartz.core.QuartzScheduler.initialize(QuartzScheduler.java:305) INFO - Scheduler meta-data: Quartz Scheduler (v2.2.1) 'NutzbookScheduler' with instanceId 'NON_CLUSTERED'
  5. Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  6. NOT STARTED.
  7. Currently in standby mode.
  8. Number of jobs executed: 0
  9. Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 3 threads.
  10. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
  11. 2015-04-24 23:07:34,708 org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1339) INFO - Quartz scheduler 'NutzbookScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
  12. 2015-04-24 23:07:34,708 org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1343) INFO - Quartz scheduler version: 2.2.1
  13. 2015-04-24 23:07:34,708 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:144) DEBUG - Get 'jobFactory'<>
  14. 2015-04-24 23:07:34,708 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - >> Load definition
  15. 2015-04-24 23:07:34,708 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=jobFactory
  16. 2015-04-24 23:07:34,709 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:137) DEBUG - Found IocObject(jobFactory) in IocLoader(QuartzIocLoader@1177174666)
  17. 2015-04-24 23:07:34,709 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:193) DEBUG - >> Make...'jobFactory'<>
  18. 2015-04-24 23:07:34,710 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:82) DEBUG - class org.nutz.integration.quartz.NutQuartzJobFactory , no config to enable AOP for this type.
  19. 2015-04-24 23:07:34,710 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:59) DEBUG - Save object 'jobFactory' to [app]
  20. 2015-04-24 23:07:34,711 org.quartz.core.QuartzScheduler.setJobFactory(QuartzScheduler.java:2311) INFO - JobFactory set to: org.nutz.integration.quartz.NutQuartzJobFactory@48de4231
  21. 2015-04-24 23:07:34,711 org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:575) INFO - Scheduler NutzbookScheduler_$_NON_CLUSTERED started.

代表各种初始化操作.