美文网首页
Spring Boot异步任务

Spring Boot异步任务

作者: shengapps | 来源:发表于2018-06-19 11:44 被阅读0次

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;

    }

相关文章

网友评论

      本文标题:Spring Boot异步任务

      本文链接:https://www.haomeiwen.com/subject/ecraeftx.html