一辈子的程序员?
爱你一生不变-芳芳!
posts - 27, comments - 15, trackbacks - 0, articles - 0
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
我的评论
re: 给我离开的勇气!!!
boddi 2008-10-07 17:18
是的,谢谢
re: Spring Quartz如何动态配置时间(3)
boddi 2007-08-11 14:56
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方法去设置呢?
re: Spring Quartz如何动态配置时间(3)
boddi 2007-08-10 12:14
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不可以一个都没有的
re: birt 2.0 is now available....占个头位,宣传一下
boddi 2006-09-06 07:36
导出excel如何进行?谢谢
re: spring、ibatis控制oracle分页的问题
boddi 2006-08-31 18:21
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有何高招吗?谢谢
re: spring、ibatis控制oracle分页的问题
boddi 2006-08-30 14:05
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不会造成很大的效率问题吗?
Powered by:
BlogJava
Copyright © boddi
日历
<
2024年11月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(10)
给我留言
查看公开留言
查看私人留言
随笔档案
2007年8月 (1)
2007年3月 (1)
2006年10月 (1)
2006年9月 (9)
2006年8月 (13)
2006年7月 (2)
搜索
最新评论
1. re: jxl实例
可以使用 ,xiexie
--insistdd
2. re: 给我离开的勇气!!![未登录]
顶,支持
--jeff
3. re: attachEvent() / addEventListener() 对象添加触发事件(转)
谢谢,转了。
--Felix021
4. re: 给我离开的勇气!!!
是的,谢谢
--boddi
5. re: 给我离开的勇气!!![未登录]
当然是去迎接狂风暴雨啦,天下何处无芳草
--zolly
阅读排行榜
1. jxl实例(6998)
2. attachEvent() / addEventListener() 对象添加触发事件(转)(5548)
3. 使用JXL读取Excel表格,拷贝、更新Excel工作薄(2957)
4. Java RMI Tutorial(2113)
5. iframe详解(1101)
评论排行榜
1. jxl实例(5)
2. 给我离开的勇气!!!(3)
3. javaexcelapplication(3)
4. 2007最新骗局:(2)
5. Java RMI Tutorial(1)