@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);
    }

结果:

 

posted @ 2020-12-10 11:03  魔杰Lee  阅读(391)  评论(0编辑  收藏  举报