zoukankan      html  css  js  c++  java
  • springmvc使用注解实现非阻塞定时器

    1、在Spring配置文件中添加

    xmlns:task="http://www.springframework.org/schema/task"
    
    
    http://www.springframework.org/schema/task
    http://www.springframework.org/schema/task/spring-task-3.2.xsd
    <context:component-scan base-package="lct.conference.timer" />
    <!-- 开启注解调度支持 @Async异步-->
    <task:executor id="executor" pool-size="5" />
    <task:annotation-driven executor="executor"/>
     

     2、

    package lct.conference.timer;
    
    import lct.conference.util.PCMSLog;
    import org.springframework.context.annotation.Lazy;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    /**
     * @Author 
     * @Date 2020/10/26 14:18
     * @Version 1.0
     * @Description 描述
     */
    @EnableAsync
    @Lazy(false)//避免spring懒加载导致无效
    @Component
    public class FlightTrainTask {
        PCMSLog pcmsLog = PCMSLog.getlog(getClass());
        @Async//开启异步,避免阻塞
        @Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行
        public void taskCycle() throws InterruptedException {
            Thread.sleep(1000*10);
            pcmsLog.info("=======================使用SpringMVC框架配置定时任务");
        }
    }

  • 相关阅读:
    Request
    HTTP
    mysql递归查询函数
    redis 6.0.9配置文件详解
    java对数据进行加密、解密
    java Base64编码、解码
    nginx基础使用
    linux指令笔记
    Spring 常用注解粗陋看法
    docker 已有容器修改容器配置
  • 原文地址:https://www.cnblogs.com/penghq/p/13878572.html
Copyright © 2011-2022 走看看