线程池的2种构造方式

package util;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

public class ThreadManage {

private static ExecutorService executorService=getExecutorService();

private static ExecutorService executorService2=test();


public static ExecutorService getExecutorService(){
ThreadFactory nameThreadFactory=new ThreadFactoryBuilder().setNameFormat("thread-pool-cuhome-%d").build();
ExecutorService executorService1=new ThreadPoolExecutor(4,8,3000, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(1024),nameThreadFactory,new ThreadPoolExecutor.AbortPolicy());
return executorService1;
}

private static ScheduledExecutorService test(){
ThreadFactory threadFactory=new ThreadFactoryBuilder().setNameFormat("thread-schdule-%d").build();
ScheduledExecutorService scheduledExecutorService=new ScheduledThreadPoolExecutor(1,threadFactory);
return scheduledExecutorService;
}


}
posted @ 2021-06-25 11:30  甜菜波波  阅读(109)  评论(0编辑  收藏  举报