whyclxw
2024-03-05 e1f01e8e70bc3ca75ad7ee25cb45c263e4631df3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.whyc.factory;
 
import com.whyc.dto.result.RealDateDTO;
import com.whyc.pojo.BattRealdata;
 
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep;
 
public class ThreadPoolExecutorFactory {
 
    private static ThreadPoolExecutor poolExecutor = init();
 
    private static ThreadPoolExecutor init() {
        //线程池初始化
        UserThreadFactory userThreadFactory = new UserThreadFactory("fg");
        ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 48, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(16), userThreadFactory,new ThreadPoolExecutor.CallerRunsPolicy());
        poolExecutor = pool;
        return pool;
    }
 
    public static ThreadPoolExecutor getPoolExecutor() {
        return poolExecutor;
    }
 
}