转自 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的更多相关文章

  1. SpringBoot整合全局异常处理&SpringBoot整合定时任务Task&SpringBoot整合异步任务

    ============整合全局异常=========== 1.整合web访问的全局异常 如果不做全局异常处理直接访问如果报错,页面会报错500错误,对于界面的显示非常不友好,因此需要做处理. 全局异 ...

  2. (入门SpringBoot)SpringBoot结合定时任务task(十)

    SpringBoot整合定时任务task 使用注解EnableScheduling在启动类上. 定义@Component作为组件被容器扫描. 表达式生成地址:http://cron.qqe2.com ...

  3. Spring注解配置定时任务<task:annotation-driven/>

    http://m.blog.csdn.net/article/details?id=50945311 首先在配置文件头部的必须要有: xmlns:task="http://www.sprin ...

  4. java中实现定时任务 task 或quartz

    转载大神的 https://www.cnblogs.com/hafiz/p/6159106.html https://www.cnblogs.com/luchangyou/p/6856725.html ...

  5. Spring3.0.6定时任务task:scheduled

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. 定时任务Task

    使用注解@EnableScheduling开启定时任务,会自动扫描 定义@Component作为组件被容器扫描 对于EnableScheduling是注解在启动类上,很多开关配置都会再启动类中进行设置 ...

  7. SpringBoot整合定时任务task

    @SpringBootApplication //扫描 mybatis mapper 包路径 @MapperScan(basePackages = "com.imooc.mapper&quo ...

  8. Spring Boot入门系列(八)整合定时任务Task,一秒搞定定时任务

    前面介绍了Spring Boot 中的整合Redis缓存已经如何实现数据缓存功能.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/categ ...

  9. 【Spring Task】定时任务详解实例-@Scheduled

    Spring的任务调度,采用注解的形式 spring的配置文件如下,先扫描到任务的类,打开spirng任务的标签 <beans xmlns="http://www.springfram ...

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:响应式图片

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Matplotlib 图形绘制

    章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...

  3. python编写banner获取的常用模块

    模块的概念:模块也叫库,每个模块中都内置了大量的功能和函数.类和变量.它就像是积木,可以根据需要进行调用组合.模块就是程序,每个模块就是一个后缀为.py的Python程序.Python的模块分为标准模 ...

  4. Windows驱动开发-符号链接和设备名

    windows下的设备是以"\Device\[设备名]”形式命名的. 例如磁盘分区的C盘,D盘的设备名称就是 "\Device\HarddiskVolume2” "\De ...

  5. 运行自己的 DaemonSet【转】

    本节以 Prometheus Node Exporter 为例演示如何运行自己的 DaemonSet. Prometheus 是流行的系统监控方案,Node Exporter 是 Prometheus ...

  6. DB2的简单操作

    转 最近在看db2,边读边写了一些,记下来,虽然写的乱七八糟.以备后用. 这些都写的很简单.我觉得也算是一些简单的操作吧,有些也是摘自别人的blog具体是引用哪的就不太记得了. 一.DB2两种注释写法 ...

  7. 微信小程序是什么

    官方的开发文档 微信小程序写的不多,随便写写 创建项目,分析工具 微信小程序有专门的编辑工具,去官网下载 然后申请一个小程序项目,获得一个appId,然后进入编辑工具就可以直接开发了 编辑工具可以设置 ...

  8. 032.SAP上用户无法打开PPE模块,查看并开通用户的PPE权限

    01. 用户使用PPE模块之后,提示没有为iPPE工作台分配一个用户参数,如图所示: 02. 如果是管理员账号,则可以点击右下角的问号,来到下面界面 03.点击iPPE 用户分配者几个蓝色的字,进入下 ...

  9. 004.CI4框架CodeIgniter, 配置mysql数据库,并进行数据库查询

    01.在app的Config目录的Database文件里面填写数据库配置,并把pConnect设置成true,此处为一直连接mysql数据库 02.在Models中,创建一个System目录,再在Sy ...

  10. 004.Delphi插件之QPlugins,参数传递

    界面如下 插件框架中大量使用了接口的东西,看的眼花缭乱,很多地方只做了申明,具体的实现是在另外的子类. DLL的代码如下 unit ParamTest; interface uses classes, ...