google MoreExecutors
import cn.hutool.core.thread.NamedThreadFactory; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.*; public class ThreadPool { /** * invoke 线程池 */ public static ExecutorService executorService = new ThreadPoolExecutor( 40, 100, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(50), new NamedThreadFactory("mian-thread",true), new ThreadPoolExecutor.CallerRunsPolicy());//超出,直接忽略 public static ListeningExecutorService backgroundRefreshPools = MoreExecutors.listeningDecorator(executorService); public static void execute(Runnable runnable){ executorService.execute(runnable); } public static <T> ListenableFuture<T> submit(Callable<T> callable){ return backgroundRefreshPools.submit(callable); } public static <T> Future<T> submitFuture(Callable<T> callable) { return executorService.submit(callable); } }