一辈子的程序员?

爱你一生不变-芳芳!
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不会造成很大的效率问题吗?