Jeesite 定时任务 Task

 

转自 http://blog.lunhui.ren/archives/280

第一种方式

一. spring-context.xml配置加入

xmlns:task=”http://www.springframework.org/schema/task”

xsi:schemaLocation下面:http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd

 

二. 继续spring-context.xml配置加入

<!– 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = “0 0 2 * * ?”)标注方法 –>
<task:executor id=”executor” pool-size=”10″/> <task:scheduler id=”scheduler” pool-size=”10″/>
<task:annotation-driven scheduler=”scheduler” executor=”executor” proxy-target-class=”true”/>

代码基于注解形式的task

 

package com.thinkgem.jeesite.modules.sys.service;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* Created by Administrator on 2016/6/22.
*/
@Service
@Lazy(false)
public class TaskJob2 {
@Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
public void job1() {
System.out.println("spring task 注解使用。。。任务进行中");
}
}

发布项目即可在输出行里看到输出结果

 

 

第二种方式

继续配置spring-context.xml加入

 

 

<task:scheduled-tasks>
<task:scheduled ref="taskJob" method="job1" cron="0/5 * * * * ?"/>
</task:scheduled-tasks>

 

task代码

 

package com.thinkgem.jeesite.modules.sys.service;
import  org.springframework.stereotype.Service;
@Service
public class TaskJob {
public void job1() {
System.out.println("任务进行中。。。");
}
}

发布项目即可在输出行里看到输出结果

 

附录:摘自其他博文

cronExpression的配置说明,具体使用以及参数请百度google

字段   允许值   允许的特殊字符

秒    0-59    , – * /

分    0-59    , – * /

小时    0-23    , – * /

日期    1-31    , – * ? / L W C

月份    1-12 或者 JAN-DEC    , – * /

星期    1-7 或者 SUN-SAT    , – * ? / L C #

年(可选)    留空, 1970-2099    , – * / 

– 区间  

* 通配符  

? 你不想设置那个字段

下面只例出几个式子

 

CRON表达式    含义 

“0 0 12 * * ?”    每天中午十二点触发 

“0 15 10 ? * *”    每天早上10:15触发 

“0 15 10 * * ?”    每天早上10:15触发 

“0 15 10 * * ? *”    每天早上10:15触发 

“0 15 10 * * ? 2005”    2005年的每天早上10:15触发 

“0 * 14 * * ?”    每天从下午2点开始到2点59分每分钟一次触发 

“0 0/5 14 * * ?”    每天从下午2点开始到2:55分结束每5分钟一次触发 

“0 0/5 14,18 * * ?”    每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发 

“0 0-5 14 * * ?”    每天14:00至14:05每分钟一次触发 

“0 10,44 14 ? 3 WED”    三月的每周三的14:10和14:44触发 

“0 15 10 ? * MON-FRI”    每个周一、周二、周三、周四、周五的10:15触发

 

 

 

posted @ 2019-08-05 10:42  雨韵蓝田  阅读(1692)  评论(0编辑  收藏  举报