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 ...
随机推荐
- Vue.js面试题
一.什么是MVVM? MVVM是Model-View-ViewModel的缩写.MVVM是一种设计思想.Model 层代表数据模型,也可以在Model中定义数据修改和操作的业务逻辑:View 代表UI ...
- CSS-lineheight
.test div{width:300px;margin:15px 0;border:1px solid #000;}.test p{margin:0;font-size:30px;}.fixed d ...
- 十九 Listener
Listener 监听器 一 监听器内部原理:其实就是接口回调 需求:A在执行循环,当循环到5的时候,通知B 事先先把某一个对象传递给A ,当A执行到5的时候,通过这个对象来调用B中的方法 但是不是直 ...
- Jquery插件---渐隐轮播
//需求:打开网页时,每秒钟自动切换下一张图片内容.也可以用鼠标点导航按钮进行图片切换 //代码如下 <!DOCTYPE html> <html lang="en" ...
- Vue的7属性-8方法-7指令
Vue的7属性: el属性 绑定id,用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符 data属性 用来组织从view中抽象出来的属性,可以说将视图的数据抽象出来存放在dat ...
- Binary Tree和Binary Search Tree
Binary TreeDefinition: at most two children node. Binary Tree Example: 10 ==root / \ 13 ...
- BVS安全检测之检查Linux是否口令生存周期
口令生存周期的配置文件为 /etc/login.defs vim 打开该文件,命令模式下输入 /PASS_MAX_DAYS 找到该配置信息的位置 我的Linux操作系统默认显示的是99999,说明我当 ...
- MySQL 批量更新、删除数据shell脚本
#!/bin/bash. ~/.bash_profilelog=/tmp/update_log_1_$(date +%F).logvstart=1step=100vstop=$((${vstart}+ ...
- Spring的AOP开发(基于ApsectJ的注解)
创建项目,导包 编写目标类并配置 创建OrderDao package com.rick.aop.demo1; public class OrderDao { public void save() { ...
- IDEA启动Tomcat报错Address localhost:1099 is already in use解决办法
问题:Error running 'lugia-web': Address loaclhost:1099 is already in use如下图 解决方法:cmd输入下面命令: netstat -a ...