javaconcurrencyexecutorserviceexecutors

Data structure inside Executors


We can provide a BlockingQueue implementations while defining ThreadPoolExecutors. However, if I use the factory (Executors) to create a single thread pool as shown below, I would like to know which blocking queue is used. I am guessing it is a LinkedBlockingQueue. The documentation talks about unbounded queue, but it does not reveal the implementation.

ExectorService service = Executors.newSingleThreadExecutor();

Solution

  • This is from Executors src:

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