转自 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. 加拿大Assignment写作如何靠第一句话来吸睛?

    最近有留学加拿大的同学咨询我们如何写好assignment的首句,关于话题背景的引入,如何才能自然精妙,让老师对后文充满期待.小编用一句话总结今天的策略:陈述一个跟话题直接相关的事实.“直接相关”,保 ...

  2. Unity Scene视图下 输出物体坐标等信息

    using UnityEditor; using UnityEngine; [CustomEditor(typeof(GameObject))] public class MyEditor : Edi ...

  3. mysql文件理解

    mysql_Innodb的undo_log和redo_log 原创 2014年10月28日 11:26:34   众所周知,mysql支持多种存储引擎,现在常用的是MyISAM和InnoDB.MyIS ...

  4. 关于导出Excel表中存在部门或用户数据权限问题

    /** * 导出Controller */ @RequiresPermissions("xxx:weeklightlimit:download") @RequestMapping( ...

  5. Linux学习计划(一)

    一.用途:网络服务器 二.优点: 1.开源免费 2.良好的可移植性 3.安全性 三.安装Linux 工具:VMware workstation .centOS7 安装步骤 图片加载中... 说明: Ⅰ ...

  6. CCF 201703-4 地铁修建(最小生成树)

    题意:A市有n个交通枢纽,其中1号和n号非常重要,为了加强运输能力,A市决定在1号到n号枢纽间修建一条地铁.地铁由很多段隧道组成,每段隧道连接两个交通枢纽.经过勘探,有m段隧道作为候选,两个交通枢纽之 ...

  7. kubernetes集群全栈监控报警方案kube-prometheus

    参考文档 http://www.servicemesher.com/blog/prometheus-operator-manual/ https://github.com/coreos/prometh ...

  8. OBS Studio 24.0 RC1 发布 – 有大惊喜

    导读 对于那些使用OBS Studio进行跨平台直播和屏幕录制需求的人来说,OBS Studio 24.0即将推出,但首先发布的是他们的候选版本,以审查进入这一重大更新的新功能. OBS Studio ...

  9. vs2010编译C++ 结构体

    //结构体的测试// CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usi ...

  10. delphi http请求用到的编码方式

    uses HttpEncode: HttpEncode(AnsiToUtf8('***'))