zoukankan      html  css  js  c++  java
  • SpringTask

    一、定时任务解决方案

        1.快速入门

           1)添加命名空间和约束     

     xmlns:task="http://www.springframework.org/schema/task"
    
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd

           2)在applicationContext.xml中添加配置      

    <task:annotation-driven></task:annotation-driven>

           3)编写案例,每秒输出当前时间 

    @Component
    public class TestController {
    
        @Scheduled(cron = "* * * * * ?")
        public void testTimeOutLogic(){
            System.out.println(new Date());
        }
    }

    二、Cron表达式

         1. Cron表达式是一个字符串,字符串以5个空格隔开,分6个工作区域,格式:

               Seconds  Minutes  Hours  DayofMonth  Month  DayofWeek 

          2.详解

              Seconds  :可出现  -  ,  *  /  四个字符,有效范围0-59的整数 (秒);

              Minutes  :可出现  -  ,  *  /  四个字符,有效范围0-59的整数(分);

              Hours  :可出现  -  ,  *  /  四个字符,有效范围0-23的整数(小时);

              DayofMonth  :可出现  -  ,  *  /  ?L W C八个字符,有效范围0-31的整数(每月中的某一天);

              Month  :可出现  -  ,  *  /  四个字符,有效范围1-12的整数(月);

              DayofWeek :可出现  -  ,  *  /  ? L C 七个字符,有效范围1-7的整数(每星期的某一天);

          3.字符的含义

              1)* : 表示匹配该域的任何值,如在Minutes域使用*,表示每分钟都会触发事件;

              2)? :只能用于DayofMonth和DayofWeek两个域,在那个域使用表示这个域不能使用;

              3)- :表示范围,如在Minutes域使用 5-20,表示在一小时内从5 -20 这个时间段内每分钟执行一次

              4)a/b :表示起始时间a开始,每个时间b触发一次,如在Minutes域使用 5/20,表示在一小时内从5分钟开始,每隔20分钟执行一次

             

  • 相关阅读:
    hdu 2222 Keywords Search 模板题
    AC自动机 (模板)
    7. 通过鼠标右键改变视角
    NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
    6. 通过鼠标滑轮控制“镜头远近”
    5. Unity脚本的执行顺序
    4. 在Inspector面板中显示类中变量+ 拓展编辑器
    NGUI 的使用教程与实例(入门)(1 )
    1. 通过移动鼠标旋转摄像机观察模型
    C#面试题
  • 原文地址:https://www.cnblogs.com/cqyp/p/12904128.html
Copyright © 2011-2022 走看看