風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數據加載中……

          Quartz應用(ZT)

          ?

            Quartz是OpenSymphony開源組織在Job scheduling領域又一個開源項目,它可以與J2EE與J2SE應用程序相結合也可以單獨使用。Quartz可以用來創建簡單或為運行十個,百個,甚至是好幾萬個Jobs這樣復雜的日程序表。Jobs可以做成標準的Java組件或 EJBs。Quartz的最新版本為Quartz 1.5.2。

          實例:

          package ?example.quartz;

          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.SchedulerFactory;

          import ?java.util.Date;

          /**
          ?*?
          @author ?kestrel
          ?
          */

          /* ?實現Job? */
          public ? class ?QuartzReport? implements ?Job? {

          ????
          /* ?重載該函數? */
          ????
          public ? void ?execute(JobExecutionContext?cntxt)? throws ?JobExecutionException? {
          ????????System.out.println(
          " Generating?report?-? "
          ????????????????????????
          + ?cntxt.getJobDetail().getJobDataMap().get( " type " )
          ????????????????????????
          + ? new ?Date());
          ????}


          ????
          public ? static ? void ?main(String[]?args)? {
          ????????
          try ? {
          ????????????SchedulerFactory?schedFact?
          = ? new ?org.quartz.impl.StdSchedulerFactory();
          ????????????Scheduler?sched?
          = ?schedFact.getScheduler();
          ????????????sched.start();
          ????????????JobDetail?jobDetail?
          = ? new ?JobDetail( " Income?Report " ,
          ????????????????????
          " Report?Generation " ,?QuartzReport. class );
          ????????????jobDetail.getJobDataMap().put(
          " type " ,? " FULL " );
          ????????????CronTrigger?trigger?
          = ? new ?CronTrigger( " Income?Report " ,
          ????????????????????
          " Report?Generation " );
          ????????????
          /* ?每1分鐘執行一次? */
          ????????????trigger.setCronExpression(
          " 0?0/1?*?*?*?? " );
          ????????????sched.scheduleJob(jobDetail,?trigger);
          ????????}
          ? catch ?(Exception?e)? {
          ????????????e.printStackTrace();
          ????????}

          ????}

          }


          Quartz的配置文件:quartz.properties
          # Configure Main Scheduler Properties
          org.quartz.scheduler.instanceName = TestScheduler
          org.quartz.scheduler.instanceId = one

          # Configure ThreadPool
          org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
          org.quartz.threadPool.threadCount =? 5
          org.quartz.threadPool.threadPriority = 4

          # Configure JobStore
          org.quartz.jobStore.misfireThreshold = 5000
          org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

          附:cronExpression配置說明

          字段

          允許值

          允許的特殊字符

          0-59

          , - * /

          0-59

          , - * /

          小時

          0-23

          , - * /

          日期

          1-31

          , - * ? / L W C

          月份

          1-12 或者 JAN-DEC

          , - * /

          星期

          1-7 或者 SUN-SAT

          , - * ? / L C #

          年(可選)

          留空, 1970-2099

          , - * /

          posted on 2006-07-18 11:00 風人園 閱讀(418) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 红桥区| 沙坪坝区| 丰县| 乐都县| 友谊县| 游戏| 阿克| 墨竹工卡县| 阳谷县| 奎屯市| 涞源县| 绍兴市| 新蔡县| 齐河县| 许昌市| 崇明县| 扎兰屯市| 建平县| 林西县| 耿马| 苍溪县| 新建县| 民丰县| 中方县| 康平县| 盈江县| 寿宁县| 宜君县| 乌兰察布市| 平潭县| 个旧市| 康保县| 铜陵市| 当阳市| 白水县| 红桥区| 张家川| 丹凤县| 巩留县| 察雅县| 视频|