我的漫漫程序之旅

          專注于JavaWeb開發(fā)
          隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
          數(shù)據(jù)加載中……

          Quartz高級部分(Spring默認(rèn)對Quartz的支持)

          在Spring中使用Quartz也是很簡單,Spring默認(rèn)你Quartz提供了支持.
          你甚至不需要添加任何額外的jar包.

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
          <beans>
              
          <bean name="quartzScheduler"
                  class
          ="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                  
          <property name="triggers">
                      
          <list>
                          
          <ref bean="cronTrigger" />
                      
          </list>
                  
          </property>
                  
          <!-- 指定你屬性文件的位置(非必須) -->
                  
          <property name="configLocation"
                      value
          ="classpath:org/quartz/quartz.properties" />
              
          </bean>

              
          <bean id="cronTrigger"
                  class
          ="org.springframework.scheduling.quartz.CronTriggerBean">
                  
          <property name="jobDetail" ref="jobDetail" />
                  
          <!--朝九晚五工作時(shí)間內(nèi)每半小時(shí)執(zhí)行一次-->
                  
          <property name="cronExpression" value="0 0/30 9-17 *,* * ?" />
              
          </bean>

              
          <!-- 使用pojo做job,指定pojo和method -->
              
          <bean id="jobDetail"
                  class
          ="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <!-- 這時(shí)關(guān)聯(lián)你的計(jì)劃類 -->
                  
          <property name="targetObject" ref="bookStockChecker" />
                  
          <!-- 你的計(jì)劃類的具體方法 -->
                  
          <property name="targetMethod" value="check" />
              
          </bean>

              
          <!-- 圖書庫存檢查類 -->
              
          <bean id="bookStockChecker" class="org.quartz.BookStockChecker"
                  autowire
          ="byName" lazy-init="true">
                  
          <!-- 這里為類的屬性初始值 -->
                  
          <property name="minStock" value="100" />
              
          </bean>
          </beans>

          資源文件:
          #============================================================================
          # 配置 Main Scheduler Properties
          #
          ============================================================================
          org.quartz.scheduler.instanceName 
          = DefaultQuartzScheduler
          org.quartz.scheduler.rmi.export 
          = false
          org.quartz.scheduler.rmi.proxy 
          = false
          org.quartz.scheduler.wrapJobExecutionInUserTransaction 
          = false

          #
          ============================================================================
          # 配置執(zhí)行線程池
          #
          ============================================================================
          org.quartz.threadPool.class 
          = org.quartz.simpl.SimpleThreadPool
          org.quartz.threadPool.threadCount 
          = 10
          org.quartz.threadPool.threadPriority 
          = 5
          org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread 
          = true

          #
          ============================================================================
          # 配置 JobStore
          #
          ============================================================================
          org.quartz.jobStore.misfireThreshold 
          = 60000

          #內(nèi)存中JobStore
          , 服務(wù)器重啟時(shí)執(zhí)行記錄會(huì)丟失
          org.quartz.jobStore.class 
          = org.quartz.simpl.RAMJobStore

          #數(shù)據(jù)庫中JobStore
          #org.quartz.jobStore.class 
          = org.quartz.impl.jdbcjobstore.JobStoreTX
          #org.quartz.jobStore.driverDelegateClass
          =org.quartz.impl.jdbcjobstore.MSSQLDelegate
          #org.quartz.jobStore.driverDelegateClass
          =org.quartz.impl.jdbcjobstore.oracle.OracleDelegate


          posted on 2008-05-09 11:13 々上善若水々 閱讀(3138) 評論(0)  編輯  收藏 所屬分類: opensource

          主站蜘蛛池模板: 南召县| 晋宁县| 昌黎县| 汝城县| 蓬安县| 辰溪县| 齐河县| 阳谷县| 招远市| 廊坊市| 普宁市| 塔城市| 鹿泉市| 阿鲁科尔沁旗| 呼和浩特市| 临洮县| 阿克| 新乡市| 苍溪县| 池州市| 台北市| 阿坝县| 全州县| 黔东| 安平县| 泊头市| 鲁山县| 宁蒗| 彭泽县| 育儿| 建德市| 长宁县| 固镇县| 攀枝花市| 白银市| 龙里县| 大悟县| 海伦市| 镇赉县| 滁州市| 房产|