· spring定时控制器配置文件实现方式

    一. 编写一个正常的业务类

public class SyncDataTaskTimer {

    private final static Logger log = Logger.getLogger(SyncDataTaskTimer.class); 

    /**
* 同步组织
*/
public void syncOrg(){
log.info("同步组织:"+System.currentTimeMillis());
}
/**
* 同步用户
*/
public void syncUser(){
log.info("同步用户:"+System.currentTimeMillis());
} }

  二. applicationContext-task.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <!-- spring定时任务配置项 -->
<bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"/> <!-- 同步ipm数据-定时任务配置 -->
<bean id="syncDataTaskTimer" class="cn.chinaunicom.pmis.interfaces.ipm.server.task.SyncDataTaskTimer"/> <!-- 任务时间项配置 -->
<task:scheduled-tasks>
<task:scheduled ref="syncDataTaskTimer" method="syncOrg" cron="0 30 23 * * ?"/>
<task:scheduled ref="syncDataTaskTimer" method="syncUser" cron="0 40 23 * * ?"/>
</task:scheduled-tasks>

  三. applicationContext.xml 引用

<!-- 支持自带定时任务配置 -->
<import resource="applicationContext-task.xml" />

  注:这里把spring的配置文件进行了拆分。

----------------------------------------分割线-----------------------------------------

  · 难点解析

  一. cron语法

    <task:scheduled ref="syncDataTaskTimer" method="syncOrg" cron="0 30 23 * * ?"/>

     cron="0 30 23 * * ?"意思为每天的23点30分执行一次。

    cron语法使用和字符解释

      cron的使用语法:

        

 (Seconds)  (Minutes)  (Hours)  (DayofMonth)  (Month)  (DayofWeek) [Year]
秒 分 时 日 月 周 [年]

  

       cron的字符意义:

        ① * : 表示在当前区域内匹配任意值,列如如果在秒上,则表示每秒都出发该事件

        ② ? : 表示任意值,使用在dayofmonth和dayofweek上

        ③ / : 使用方式5/15,假如写在秒所在区域上,左边是开始时间,右边是在隔15秒后执行,所以执行频率是, 5秒执行一次,20秒执行一次,35,50

        ④ - : 表示一个区间,如果在分钟区域1-5,其时间内每分钟执行一次

        ⑤ , : 枚举值,在分钟位置上5,15,31,代表这5分,15分,31分各执行一次

        ⑥ # : 2#3,每个月第三个周的星期一(1代表日,2代表星期一)

        ⑦ L : 最后的意思,使用在dayofmonth和dayofweek上,如放在dayofweek=6L,意思是星期五触发。

        ⑧ W :正常工作日周一到周五

        ⑨ LW:每个月最后的一个周五

      

      在网上摘抄一些例子,基本上都包含了,

      

“0 0 12 * * ?” 每天12:00触发事件
“0 15 10 ? * *” 每天10:15触发事件
“0 15 10 * * ?” 每天10:15触发事件
“0 15 10 * * ? *” 每天10:15触发事件
“0 15 10 * * ? 2005″ 2005年的每天10:15触发事件
“0 * 14 * * ?” 每天14点开始触发,每分钟触发一次,14:59分结束
“0 0/5 14 * * ?” 每天14点开始触发到14:59分结束的每5分钟触发一次事件
“0 0/5 14,18 * * ?” 每天14点开始到14:59期间和18点到18:59期间的每5分钟触发一次事件
“0 0-5 14 * * ?” 每天14点到14:05期间的每1分钟触发一次事件
“0 10,44 14 ? 3 WED” 每年3月的星期三的14:10和14:44触发一次事件
“0 15 10 ? * MON-FRI” 周一至周五的10:15触发一次事件
“0 15 10 15 * ?” 每月15日10:15触发一次事件
“0 15 10 L * ?” 每月最后一日的10:15触发一次事件
“0 15 10 ? * 6L” 每月的最后一个星期五10:15触发一次事件
“0 15 10 ? * 6L 2002-2005″ 2002年至2005年的每月的最后一个星期五10:15触发一次事件
“0 15 10 ? * 6#3″ 每月的第三个星期五10:15触发一次事件

Spring-task-timer定时器的更多相关文章

  1. [Java定时器]用Spring Task实现一个简单的定时器.

    今天做一个项目的的时候需要用到定时器功能.具体需求是: 每个月一号触发一次某个类中的方法去拉取别人的接口获取上一个月份车险过期的用户.如若转载请附上原文链接:http://www.cnblogs.co ...

  2. java Quartz定时器任务与Spring task定时的几种实现,

    java Quartz定时器任务与Spring task定时的几种实现 基于java 的定时任务实现, Quartz 时间详细配置    请查阅   http://www.cnblogs.com/si ...

  3. 任务调度的方式:Timer、ScheduledExecutorService、spring task、quartz、XXL-JOB、Elastic-Job

    任务调度 定时任务调度:基于给定的时间点.给定的时间间隔.给定的执行次数自动执行的任务. Timer 介绍 Timer,简单无门槛,一般也没人用. Timer位于java.util包下,其内部包含且仅 ...

  4. java定时任务实现的几种方式(Timer、Spring Task、Quartz)

    Timer JDK自带的Timer类,允许调度一个TimerTask任务. Demo: /** * Timer测试类 */ public class TimerDemo { public static ...

  5. spring task定时器的配置使用

    spring task的配置方式有两种:配置文件配置和注解配置. 1.配置文件配置 在applicationContext.xml中增加spring task的命名空间: xmlns:task=&qu ...

  6. 任务调度 Spring Task 4(一)

    深入浅出spring task定时任务 在工作中有用到spring task作为定时任务的处理,spring通过接口TaskExecutor和TaskScheduler这两个接口的方式为异步定时任务提 ...

  7. spring task 配置

    Spring对Quartz作了一个封装,同时,Spring自己也提供了一个任务定时器(spring-task),现把它总结一下.    对于Quartz,我们使用的时候主要是注重两个方面,一个是定时任 ...

  8. Quartz Spring与Spring Task总结

    Spring对Quartz作了一个封装,同时,Spring自己也提供了一个任务定时器(spring-task),现把它总结一下.    对于Quartz,我们使用的时候主要是注重两个方面,一个是定时任 ...

  9. 关于Spring定时任务(定时器)用法

    Spring定时任务的几种实现 Spring定时任务的几种实现 一.分类 从实现的技术上来分类,目前主要有三种技术(或者说有三种产品): 从作业类的继承方式来讲,可以分为两类: 从任务调度的触发时机来 ...

  10. uartz Spring与Spring Task总结

    Spring对Quartz作了一个封装,同时,Spring自己也提供了一个任务定时器(spring-task),现把它总结一下.    对于Quartz,我们使用的时候主要是注重两个方面,一个是定时任 ...

随机推荐

  1. csuoj 1115: 最短的名字

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 1115: 最短的名字 Time Limit: 5 Sec  Memory Limit: 6 ...

  2. [转]数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

    一.MySQL   MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换 服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失 ...

  3. MES: ESB

    ESB定义了消息的收发和收发池,对于各种通讯方式定义了收发API,在收到信息后由eventBus来发布消息 ISender: public abstract interface ISender { p ...

  4. POJ 1286 Necklace of Beads(Polya原理)

    Description Beads of red, blue or green colors are connected together into a circular necklace of n ...

  5. [转]ms sql 2000 下批量 附加/分离 数据库(sql语句)

    这次公司要把MS SQL Server 2000 服务器上的数据库复制到新的服务器上面去,于是几百个数据库文件就交给我附加到新服务器上了   以前一直没接触过这方面的东西,于是果断谷歌了也百度了  找 ...

  6. 夺命雷公狗---Thinkphp----5之数据库的链接

    我们打开WEB目录下发现了Common和Home以及Runtime这三个文件夹 那么我们第一个目标是完成网站后台的首页吧,那么我们就直接将Home的文件夹复制一份出来,并且改名为Admin这样就可以分 ...

  7. 《zw版Halcon与delphi系列原创教程》发布说明

    <zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo..  ...

  8. access链接最原始代码,两种

    using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web ...

  9. servlet、genericservlet、httpservlet之间的区别(转)

    当编写一个servlet时,必须直接或间接实现servlet接口,最可能实现的方法就是扩展javax.servlet.genericservlet或javax.servlet.http.httpser ...

  10. Oracle的导入导出

    写批处理文件的基础知识 http://blog.chinaunix.net/uid-20672257-id-3056546.html http://wenku.baidu.com/view/db9c5 ...