· 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. C++之路进阶——hdu2222(Keywords Search)

    /*Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...

  2. C++之路进阶——codevs2460(树的统计)

    2460 树的统计 2008年省队选拔赛浙江  时间限制: 2 s  空间限制: 128000 KB  题目等级 : 大师 Master       题目描述 Description 一棵树上有n个节 ...

  3. ZOJ 3545 Rescue the Rabbit(AC自动机+状压DP)(The 2011 ACM-ICPC Asia Dalian Regional Contest)

    Dr. X is a biologist, who likes rabbits very much and can do everything for them. 2012 is coming, an ...

  4. CentOS 5.5 Nginx+JDK+MySQL+Tomcat(jsp)成功安装案例

    在CentOS 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的.只需yum安装环境包和nginx.解压安装jdk和tomcat.配置profile文件.server.xml和ng ...

  5. Repeater 时间格式化

    Repeater 时间格式化   <%# Eval("AboutDate","{0:yyyy-MM-dd hh:mm:ss}")%> 个人认为最好用 ...

  6. Immediate assertion

    Imemdiate assertion可以放在任何procedural statement中, assertion被执行判断,当这个procedural code被执行的时候.其他时间是不会被执行的. ...

  7. Sinatra+SQLite3+DataMapper - 十分完整的tutorial - “Superdo”

    原文地址:https://ididitmyway.herokuapp.com/past/2010/3/30/superdo_a_sinatra_and_datamapper_to_do_list/ 这 ...

  8. php+jquery注册实例

    写了一个简单的PHP+jQuery注册模块,需要填写的栏目包括用户名.邮箱.密码.重复密码和验证码,其中每个栏目需要具备的功能和要求如下图: 在做这个模块的时候,很大程度上借鉴了网易注册( http: ...

  9. 12个滑稽的C语言面试问答——《12个有趣的C语言问答》评析(5)

    前文链接:http://www.cnblogs.com/pmer/archive/2013/09/17/3327262.html A,局部变量的返回地址 Q:下面的代码有问题吗?如果有,如何修改? # ...

  10. Visual studio 中编译错误SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.

    把写好的sql脚本,并在mssqlmanager里面编译成功的存储过程脚本复制到vs项目下,出现错误信息如下:SQL71006: Only one statement is allowed per b ...