newSingleThreadExecutor和newFixedThreadPool(1)之间的区别

时间:2019-11-01 06:52:31

标签: java multithreading java.util.concurrent threadpoolexecutor

在内部,newSingleThreadExecutor()newFixedThreadPool()创建ThreadPoolExecutor对象,然后newSingleThreadExecutor()newFixedThreadPool(1)有什么区别?为什么Java有这些方法?

newFixedThreadPoo

 public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                                      0L, TimeUnit.MILLISECONDS,
                                      new LinkedBlockingQueue<Runnable>());
    }

newSingleThreadExecutor

public static ExecutorService newSingleThreadExecutor() {
        return new FinalizableDelegatedExecutorService
            (new ThreadPoolExecutor(1, 1,
                                    0L, TimeUnit.MILLISECONDS,
                                    new LinkedBlockingQueue<Runnable>()));
    }

0 个答案:

没有答案