zoukankan      html  css  js  c++  java
  • Spring定时任务的几种实现

    参考地址: http://gong1208.iteye.com/blog/1773177

      用的Spring Boot 使得配置变得简化,无需在其他地方加入任何配置文件;

      定时任务的代码可以写在controller层,也可以写在service,代码实现一样,具体根据实际业务来看,我的实现业务直接在服务层实现;

      定时任务的关键字是 @EnableScheduling (具体自行百度)

    /**
     * 定时任务配置类
     */
    @Configuration
    @EnableScheduling // 启用定时任务
    public class SchedulingConfig {
    
        private final Logger logger = LoggerFactory.getLogger(getClass());
        
        @Resource
        private BidMapper bidMapper;
    
        @Scheduled(cron = "0/20 * * * * ?") // 每20秒执行一次
        public void scheduler() {
            bidMapper.updateForTimer();
            logger.info(">>>>>>>>>>>>> 定时任务执行成功 ... ");
        }
    }
  • 相关阅读:
    Android之帧动画2
    CSS之图片关闭
    JAVA之While语句、Do和For语句
    oracle 无效字符
    java 时间制
    mybatis jdbcType date没有时分秒
    log4j说明
    spy 日志说明
    linux更新系统时间
    linux常用命令2
  • 原文地址:https://www.cnblogs.com/xx0405/p/6768464.html
Copyright © 2011-2022 走看看