zoukankan      html  css  js  c++  java
  • 一个简单的Spring定时器例子 注解方式

    首先在applicationContext.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.xsd
    <beans xmlns:task="http://www.springframework.org/schema/task"
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd" >

    <!-- 定义使用注解自动扫描的包 -->
    <context:component-scan base-package="xxx" /> 定时器必须属于扫描的包中

    <!-- 打开定时器开关 -->

    <task:annotation-driven/>

    下面是定时器的写法

    fixedDelay = 5000 表示每隔5秒执行
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    
    @Component  
    public class TestJob {
        @Scheduled(fixedDelay = 5000) 
        public void test()
        {
            System.out.println("job 开始执行"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        } 
    }
  • 相关阅读:
    Python os.getcwd()方法
    Python os.walk()方法
    PyTorch 模型构造
    Python map()函数
    字符串转数字测试--知识备忘
    如何判断一个变量是数组Array类型--实例--加个人见解
    js面试题
    ios学习笔记
    读取图片文件--实例
    名言记录
  • 原文地址:https://www.cnblogs.com/mingf123/p/3861094.html
Copyright © 2011-2022 走看看