搜定时任务时,看到别人知道集中方法,目前我也就只会一种,以后学习了再补充。
框架是ssh+mybaties。
在spring-context.xml中:
<task:scheduled-tasks scheduler="myScheduler" >
<task:scheduled ref="customAction" method="starter" cron = "0 30 17 * * ?"/>
</task:scheduled-tasks>
<task:scheduler id="myScheduler" pool-size="10"/>
ref是bean配置中的action
<bean id="customAction" class="com.herysoft.scm.struts.lease.CustomAction" scope="prototype">
<property name="customBiz" ref="customBiz" />
</bean>
method 是此action中的自定义定时任务的方法 cron是定时时间,包括7个字段:秒、分、小时、月内日期、月、周内日期、年(可选字段)。上表达式代表每天17:30:00,具体定义可以百度。
如果是多个action的定时任务可以在task内直接添加<task:scheduled ref="**Action" method="starter" cron = "时间"/>