一輩子的程序員?

          愛你一生不變-芳芳!
          posts - 27, comments - 15, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          我的評論

          re: 給我離開的勇氣!!! boddi 2008-10-07 17:18  
          是的,謝謝

          thrank you!
            是這樣的,客戶有個需求是可以自己修改任務的間隔時間的!(這個值是設置到數據庫中的),因為SimpleTriggerBean必須設置repeatInterval屬性,而這個值因為是保存在數據中的,所以我想設置兩個定時任務CMSTransformCRMTrigger和ScheduleInfoActionTrigger,ScheduleInfoActionTrigger在CMSTransformCRMTrigger任務執行前觸發:其目的是為CMSTransformCRMTrigger根據數據庫的值設置其repeatInterval屬性,配置文件如下:

              <bean id="CMSTransformCRMEngine" class="org.springframework.aop.framework.ProxyFactoryBean">
                  
          <property name="targetSource">
                      
          <bean class="org.springframework.aop.target.SingletonTargetSource">
                          
          <constructor-arg>
                              
          <bean class="com.server.business.cms.CMSTransformCRMEngine"/>
                          
          </constructor-arg>
                      
          </bean>
                  
          </property>
                  
          <property name="interceptorNames">
                      
          <list>
                          
          <value>CallContextInterceptor</value>
                      
          </list>
                  
          </property>
              
          </bean>

           
          <bean id="CMSTransformCRMJob" class="org.springframework.scheduling.quartz.JobDetailBean">         
                  
          <property name="jobClass">
                      
          <value>com.wisecrm.server.business.cms.CMSTransformCRMScheduledTask</value>
                  
          </property>    
                  
          <property name="jobDataAsMap">
                      
          <map>
                          
          <entry key="cmsTranCRMEnginer">
                              
          <ref bean="CMSTransformCRMEngine"></ref>
                          
          </entry>
                      
          </map>
                  
          </property>
              
          </bean>
              
               
          <bean id="CMSTransformCRMTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="CMSTransformCRMJob"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>90000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>90000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="ScheduleInfoAction" class="com.wisecrm.server.business.cms.ScheduleInfoAction">         
                  
          <property name="dataSource" ref="DataSource"/>     
                  
          <property name="scheduler" ref="schedulerFactory"/>     
              
          </bean>
              
              
          <bean id="ScheduleInfoActionFactory" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <property name="targetObject" ref="ScheduleInfoAction"/>
                  
          <property name="targetMethod">
                       
          <value>setTaskTimeByPreference</value>
                  
          </property>
                  
          <!--property name="arguments">
                      <list>
                          <ref local="DataSource"/>
                          <ref local="schedulerFactory"/>
                      </list>
                  </property
          -->
                  
          <property name="concurrent" value="false"/>
              
          </bean>
              
              
          <bean id="ScheduleInfoActionTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="ScheduleInfoActionFactory"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>80000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>50000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">         
                  
          <property name="triggers">             
                      
          <list>                 
                          
          <ref local="CMSTransformCRMTrigger"/>             
                          
          <ref local="ScheduleInfoActionTrigger"/>             
                      
          </list>         
                  
          </property>
              
          </bean>


          ScheduleInfoAction是動態設置間隔時間的接口:

          public class ScheduleInfoAction {

              
          private Scheduler scheduler;

              
          public void setTaskTimeByPreference() throws SchedulerException 
          {
                  
          if (isStartCMSTransformCRMTask()) 
          {
                      SimpleTriggerBean trigger 
          = (SimpleTriggerBean) scheduler.getTrigger("ScheduleInfoActionTrigger
          ",
                                      Scheduler.DEFAULT_GROUP);
                      trigger.setRepeatInterval(Long.parseLong(Application.getSystemSettingService().getPrefValue(
          "CMSPeriod
          ")));
                      scheduler.rescheduleJob(
          "ScheduleInfoActionTrigger
          ",
                              Scheduler.DEFAULT_GROUP, trigger);
                  }
           
          else {
                      scheduler.shutdown();
                  }

              }


              public
           boolean isStartCMSTransformCRMTask() {
                  
          return Application.getSystemSettingService().getPrefValue("CMSPeriod"!= null
          ;
              }


              public
           Scheduler getScheduler() {
                  
          return scheduler;
              }


              public
           void setScheduler(Scheduler scheduler) {
                  
          this.scheduler 
          = scheduler;
              }


          }

            但是不知為和兩個任務都不執行?

          后面我再在程序啟動時就通過ScheduleInfoAction的factoryBean

          設置CMSTransformCRMTrigger其repeatInterval屬性,只保留一個定時任務就可以了,

          配置如下:


          <bean id="ScheduleInfoAction" class="com.wisecrm.server.business.cms.ScheduleInfoAction">         
                  
          <property name="scheduler" ref="schedulerFactory"/>     
              
          </bean>
              
              
          <bean id="ScheduleInfoActionFactory" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <property name="targetObject" ref="CMSTransformCRMEngine"/>
                  
          <property name="targetMethod">
                       
          <value>run</value>
                  
          </property>
                  
          <property name="concurrent" value="false"/>
              
          </bean>
              
              
          <bean id="ScheduleInfoActionTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="ScheduleInfoActionFactory"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>80000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>80000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">         
                  
          <property name="triggers">             
                      
          <list>            
                          
          <ref bean="ScheduleInfoActionTrigger"/>             
                      
          </list>         
                  
          </property>
              
          </bean>


          但總感覺到有點笨拙,你幫忙參考下,為什么repeatInterval不能通過繼承SimpleTriggerBean復寫getRepeatInterval方法去設置呢?

          thrank you!
            是這樣的,客戶有個需求是可以自己修改任務的間隔時間的!(這個值是設置到數據庫中的),因為SimpleTriggerBean必須設置repeatInterval屬性,而這個值因為是保存在數據中的,所以我想設置兩個定時任務CMSTransformCRMTrigger和ScheduleInfoActionTrigger,ScheduleInfoActionTrigger在CMSTransformCRMTrigger任務執行前觸發:其目的是為CMSTransformCRMTrigger根據數據庫的值設置其repeatInterval屬性,配置文件如下:
              <bean id="CMSTransformCRMEngine" class="org.springframework.aop.framework.ProxyFactoryBean">
                  
          <property name="targetSource">
                      
          <bean class="org.springframework.aop.target.SingletonTargetSource">
                          
          <constructor-arg>
                              
          <bean class="com.server.business.cms.CMSTransformCRMEngine"/>
                          
          </constructor-arg>
                      
          </bean>
                  
          </property>
                  
          <property name="interceptorNames">
                      
          <list>
                          
          <value>CallContextInterceptor</value>
                      
          </list>
                  
          </property>
              
          </bean>

           
          <bean id="CMSTransformCRMJob" class="org.springframework.scheduling.quartz.JobDetailBean">         
                  
          <property name="jobClass">
                      
          <value>com.wisecrm.server.business.cms.CMSTransformCRMScheduledTask</value>
                  
          </property>    
                  
          <property name="jobDataAsMap">
                      
          <map>
                          
          <entry key="cmsTranCRMEnginer">
                              
          <ref bean="CMSTransformCRMEngine"></ref>
                          
          </entry>
                      
          </map>
                  
          </property>
              
          </bean>
              
               
          <bean id="CMSTransformCRMTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="CMSTransformCRMJob"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>90000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>90000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="ScheduleInfoAction" class="com.wisecrm.server.business.cms.ScheduleInfoAction">         
                  
          <property name="dataSource" ref="DataSource"/>     
                  
          <property name="scheduler" ref="schedulerFactory"/>     
              
          </bean>
              
              
          <bean id="ScheduleInfoActionFactory" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <property name="targetObject" ref="ScheduleInfoAction"/>
                  
          <property name="targetMethod">
                       
          <value>setTaskTimeByPreference</value>
                  
          </property>
                  
          <!--property name="arguments">
                      <list>
                          <ref local="DataSource"/>
                          <ref local="schedulerFactory"/>
                      </list>
                  </property
          -->
                  
          <property name="concurrent" value="false"/>
              
          </bean>
              
              
          <bean id="ScheduleInfoActionTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="ScheduleInfoActionFactory"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>80000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>50000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">         
                  
          <property name="triggers">             
                      
          <list>                 
                          
          <ref local="CMSTransformCRMTrigger"/>             
                          
          <ref local="ScheduleInfoActionTrigger"/>             
                      
          </list>         
                  
          </property>
              
          </bean>

          ScheduleInfoAction是動態設置間隔時間的接口:
          public class ScheduleInfoAction {

              
          private Scheduler scheduler;

              
          public void setTaskTimeByPreference() throws SchedulerException {
                  
          if (isStartCMSTransformCRMTask()) {
                      SimpleTriggerBean trigger 
          = (SimpleTriggerBean) scheduler.getTrigger("ScheduleInfoActionTrigger",
                                      Scheduler.DEFAULT_GROUP);
                      trigger.setRepeatInterval(Long.parseLong(Application.getSystemSettingService().getPrefValue(
          "CMSPeriod")));
                      scheduler.rescheduleJob(
          "ScheduleInfoActionTrigger",
                              Scheduler.DEFAULT_GROUP, trigger);
                  }
           
          else {
                      scheduler.shutdown();
                  }

              }


              public
           boolean isStartCMSTransformCRMTask() {
                  
          return Application.getSystemSettingService().getPrefValue("CMSPeriod"!= null;
              }


              public
           Scheduler getScheduler() {
                  
          return scheduler;
              }


              public
           void setScheduler(Scheduler scheduler) {
                  
          this.scheduler = scheduler;
              }


          }
            但是不知為和兩個任務都不執行?
          后面我再在程序啟動時就通過ScheduleInfoAction的factoryBean
          設置CMSTransformCRMTrigger其repeatInterval屬性,只保留一個定時任務就可以了,
          配置如下:
          <bean id="ScheduleInfoAction" class="com.wisecrm.server.business.cms.ScheduleInfoAction">         
                  
          <property name="scheduler" ref="schedulerFactory"/>     
              
          </bean>
              
              
          <bean id="ScheduleInfoActionFactory" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                  
          <property name="targetObject" ref="CMSTransformCRMEngine"/>
                  
          <property name="targetMethod">
                       
          <value>run</value>
                  
          </property>
                  
          <property name="concurrent" value="false"/>
              
          </bean>
              
              
          <bean id="ScheduleInfoActionTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">         
                  
          <property name="jobDetail">
                      
          <ref bean="ScheduleInfoActionFactory"></ref>
                  
          </property>    
                  
          <property name="startDelay">
                      
          <value>80000</value>
                  
          </property>
                  
          <property name="repeatInterval">
                      
          <value>80000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">         
                  
          <property name="triggers">             
                      
          <list>            
                          
          <ref bean="ScheduleInfoActionTrigger"/>             
                      
          </list>         
                  
          </property>
              
          </bean>
          但總感覺到有點笨拙,你幫忙參考下
          re: javaexcelapplication boddi 2007-06-07 15:35  
          其實excel的sheet不可以一個都沒有的
          導出excel如何進行?謝謝
          SELECT wjbh,wjmc FROM (SELECT row_.*, rownum rownum_ FROM (select wjbh,wjmc,rownum rn from y_wjlx) row_ WHERE rownum <= #end#) WHERE rownum_ > #start#
          在SQLSERVER中無法實現啊!請問SQLSERVER有何高招嗎?謝謝
          SELECT wjbh,wjmc FROM (SELECT row_.*, rownum rownum_ FROM (select wjbh,wjmc,rownum rn from y_wjlx) row_ WHERE rownum <= #end#) WHERE rownum_ > #start#
          中的select wjbh,wjmc,rownum rn from y_wjlx不會造成很大的效率問題嗎?
          主站蜘蛛池模板: 阿城市| 崇义县| 深泽县| 长阳| 银川市| 仁怀市| 克什克腾旗| 宜黄县| 错那县| 江源县| 集贤县| 平乐县| 长兴县| 三门峡市| 峨山| 西充县| 彭阳县| 汶川县| 鹤峰县| 杨浦区| 富蕴县| 且末县| 新竹县| 通渭县| 阳西县| 麻城市| 马公市| 廉江市| 洛浦县| 叙永县| 屏东县| 安顺市| 麦盖提县| 铁岭县| 涟源市| 那曲县| 安塞县| 克什克腾旗| 新绛县| 东至县| 嵊州市|