zoukankan      html  css  js  c++  java
  • @schedule

    1-加@Async,配置多线程后,同一个

    @Scheduled(cron = "0/5 * * * * ?")
    @Async(value = "asyncPoolTaskExecutor")
    public void doSendTest(){}
    方法中,不会等到方法执行完后再执行下次任务,而是异步按时间规则继续执行任务。


    测试代码及结果
    @Scheduled(cron = "0/5 * * * * ?")
        @Async(value = "asyncPoolTaskExecutor")
        public void doSendTest(){
            long id = Thread.currentThread().getId();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String format = DateUtil.format(new Date(), "HH:mm:ss");
            log.info("{},task 001---thread--{}",format,id);
        }

    结果:

  • 相关阅读:
    虚拟机网络配置常见问题总结
    Python
    Python
    Python
    Python
    Python
    Python
    MySQL
    MySQL
    MySQL
  • 原文地址:https://www.cnblogs.com/mjbenkyo/p/14113156.html
Copyright © 2011-2022 走看看