线程池创建模版

复制代码
@Configuration
public class CouponTaskThreadPoolConfig {

    @Bean("couponTaskExecutor")
    public ExecutorService couponTaskExecutor() {
        ThreadFactory threadFactory = new ThreadFactory() {
            private final AtomicInteger threadNumber = new AtomicInteger(1);
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r, "coupon-task-pool-" + threadNumber.getAndIncrement());
                thread.setDaemon(false);
                return thread;
            }
        };

        return new ThreadPoolExecutor(
                5,
                20,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                threadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}
相关推荐
TE-茶叶蛋1 小时前
`@interface` 解析
java
摇滚侠1 小时前
Java 项目教程《黑马商城》微服务拆分 05 - 10
java·开发语言·微服务
PPPPickup1 小时前
实习日志5.7
java
_Evan_Yao1 小时前
return 的迷途:try-catch-finally 中 return 的诡异顺序与 Spring 事务暗坑
java·后端·spring·mybatis
薛定谔的猫喵喵1 小时前
Spring Boot Jar包修改配置文件和Class中硬编码IP的完整指南
java·spring boot·反编译·class
Seven971 小时前
Tomcat Request请求处理过程:Connector
java
Mr数据杨1 小时前
【Codex】搭建教学中心数据工作台统筹教案与课件资源
java·开发语言·django·codex·项目开发
摇滚侠1 小时前
Java 项目教程《黑马商城》服务治理 11 - 14
java·微服务·架构
一只大袋鼠1 小时前
Spring 事务管理三种实现方式
java·数据库·spring·声明式事务