Spring Boot异步任务

2018-06-19  本文已影响0人  shengapps

Spring Boot异步任务,必须在Application配置以下信息。

1. @EnableAsync

2. 注册名为taskExecutor的Bean:

@Bean(name="taskExecutor")

    public TaskExecutor workExecutor() {

        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

        threadPoolTaskExecutor.setThreadNamePrefix("Async-");

        threadPoolTaskExecutor.setCorePoolSize(3);

        threadPoolTaskExecutor.setMaxPoolSize(3);

        threadPoolTaskExecutor.setQueueCapacity(600);

        threadPoolTaskExecutor.afterPropertiesSet();

        logger.info("ThreadPoolTaskExecutor set");

        return threadPoolTaskExecutor;

    }

上一篇下一篇

猜你喜欢

热点阅读