whycxzp
2024-03-18 26e5eed0f17b77b76310ab06d221ad996a654530
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("SNMP");
        ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 48, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(16), userThreadFactory,new ThreadPoolExecutor.AbortPolicy());
        poolExecutor = pool;
        return pool;
    }
 
    public static ThreadPoolExecutor getPoolExecutor() {
        return poolExecutor;
    }
 
}