whycxzp
2025-06-11 02ccfc21d5d4f767bbd92ecda89cdfcc3283728c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.whyc.factory;
 
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
 
public class ThreadPoolExecutorFactory {
 
    private static ThreadPoolExecutor poolExecutor = init();
 
    private static ThreadPoolExecutor init() {
        //线程池初始化,拒绝策略为丢弃
        UserThreadFactory userThreadFactory = new UserThreadFactory("br");
        ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 48, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(16), userThreadFactory,new ThreadPoolExecutor.AbortPolicy());
        poolExecutor = pool;
        return pool;
    }
 
    public static ThreadPoolExecutor getPoolExecutor() {
        return poolExecutor;
    }
 
}