@@ -18,17 +18,12 @@ public class ThreadPool {
1818 private static int maximumPoolSize = 3 ;
1919 private static long keepAliveTime = 1000 ;
2020 private static TimeUnit timeUnit = TimeUnit .MILLISECONDS ;
21- private static BlockingQueue <Runnable > workQueue = new LinkedBlockingQueue <Runnable >(1 );
22- private static ThreadFactory threadFactory = new ThreadFactory () {
23- @ Override
24- public Thread newThread (Runnable r ) {
25- return new Thread (r );
26- }
27- };
21+ private static BlockingQueue <Runnable > workQueue = new LinkedBlockingQueue <>(1 );
22+ private static ThreadFactory threadFactory = Thread ::new ;
2823 /**
2924 * 新的线程池
3025 */
31- public ThreadPoolExecutor newExecutor = null ;
26+ public ThreadPoolExecutor newExecutor ;
3227
3328 /**
3429 * 新建线程池
@@ -39,21 +34,17 @@ public Thread newThread(Runnable r) {
3934 * @param unit 存活时长单位
4035 */
4136 public ThreadPool (int core , int maximum , int keep , TimeUnit unit ) {
42- BlockingQueue <Runnable > queue = new LinkedBlockingQueue <Runnable >(1 );
43- ThreadFactory factory = new ThreadFactory () {
44- @ Override
45- public Thread newThread (Runnable r ) {
46- return new Thread (r );
47- }
48- };
37+ BlockingQueue <Runnable > queue = new LinkedBlockingQueue <>(1 );
38+ ThreadFactory factory = Thread ::new ;
4939 newExecutor = new ThreadPoolExecutor (core , maximum , keep , unit , queue , factory );
5040 }
5141
5242 /**
5343 * 初始化线程池
5444 */
5545 public static void init () {
56- executor = new ThreadPoolExecutor (corePoolSize , maximumPoolSize , keepAliveTime , timeUnit , workQueue , threadFactory );
46+ executor = new ThreadPoolExecutor (corePoolSize , maximumPoolSize , keepAliveTime , timeUnit , workQueue ,
47+ threadFactory );
5748 }
5849
5950 /**
0 commit comments