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触发
Jeesite 定时任务 Task的更多相关文章
- SpringBoot整合全局异常处理&SpringBoot整合定时任务Task&SpringBoot整合异步任务
============整合全局异常=========== 1.整合web访问的全局异常 如果不做全局异常处理直接访问如果报错,页面会报错500错误,对于界面的显示非常不友好,因此需要做处理. 全局异 ...
- (入门SpringBoot)SpringBoot结合定时任务task(十)
SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...
- Spring注解配置定时任务<task:annotation-driven/>
http://m.blog.csdn.net/article/details?id=50945311 首先在配置文件头部的必须要有: xmlns:task="http://www.sprin ...
- java中实现定时任务 task 或quartz
转载大神的 https://www.cnblogs.com/hafiz/p/6159106.html https://www.cnblogs.com/luchangyou/p/6856725.html ...
- Spring3.0.6定时任务task:scheduled
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 定时任务Task
使用注解@EnableScheduling开启定时任务,会自动扫描 定义@Component作为组件被容器扫描 对于EnableScheduling是注解在启动类上,很多开关配置都会再启动类中进行设置 ...
- SpringBoot整合定时任务task
@SpringBootApplication //扫描 mybatis mapper 包路径 @MapperScan(basePackages = "com.imooc.mapper&quo ...
- Spring Boot入门系列(八)整合定时任务Task,一秒搞定定时任务
前面介绍了Spring Boot 中的整合Redis缓存已经如何实现数据缓存功能.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/categ ...
- 【Spring Task】定时任务详解实例-@Scheduled
Spring的任务调度,采用注解的形式 spring的配置文件如下,先扫描到任务的类,打开spirng任务的标签 <beans xmlns="http://www.springfram ...
随机推荐
- Day 1:思考
干游戏这行从实习到工作算起来也有快7年的时间了, 7年的时间~上学了.毕业了.工作了.结婚了.孩子要出生了~ 也算是经历了不少的事情了,自己觉得生活过的是越来越好了, 自己做过的游戏也不算少了,不过真 ...
- L2-012. 关于堆的判断(最小堆)
将一系列给定数字顺序插入一个初始为空的小顶堆H[].随后判断一系列相关命题是否为真.命题分下列几种: “x is the root”:x是根结点: “x and y are siblings”:x和y ...
- PHPXhprof扩展在windows安装
1.下载在这里 http://dev.freshsite.pl/php-extensions/xhprof.html.(找不到资源可以私我我给你,这个上传不了资源) 注意:一定要找对应的php版本,t ...
- 2019年第十届蓝桥杯【C++省赛B组】
试题 A: 组队 本题总分:5 分 作为篮球队教练,你需要从以下名单中选出 1 号位至 5 号位各一名球员,组成球队的首发阵容.每位球员担任 1 号位至 5 号位时的评分如下表所示.请你计算首发阵容 ...
- 054、Java中使用for循环第二种写法实现1~100的累加
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- C# enable为false时不变颜色
[System.Runtime.InteropServices.DllImport("user32.dll ")] public static ex ...
- 解决oracle 11g 导出空表的方法
ORACLE 11G中有个新特性,当表无数据时,不分配segment,以节省空间. 解决方法: 1)insert一行,再rollback就产生segment了 该方法是在在空表中插入数据,再删除,则产 ...
- 04 MySQL数据类型
MySQL支持的数据类型 1.数值类型: a.整数类型 TINYINT 1字节 有符号(-128~127); 无符号(0~255) SMALLINT 2字节 有符号(-3276 ...
- MySQL报错注入函数汇总及常用注入语句
版权声明:本文转载自网络内容,下面附原创链接原创链接:https://blog.csdn.net/Auuuuuuuu/article/details/91415165 常用函数 字符串连接函数,将多个 ...
- Windows按键消息—虚拟键码(转)
源地址:http://c.biancheng.net/cpp/html/1253.html 虚拟键码保存在WM_KEYDOWN.WM_KEYUP.WM_SYSKEYDOWN和WM_SYSKEYUP消息 ...