'JAVA ThreadPoolExecutor workqueue with Callable

Java ExecutorService.newFixedThreadPool() internally using a LinkedBlockingQueue<Runnable>() as below:

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

I am wondering when I call ExecutorService.submit(Callable<?>) with callable, how it is pushed into workQueue. As per docs, only Runnable are pushed to workQueue, then what happens to Callable when all threads are busy. Where these are kept for later processing.

As per docs

workQueue - the queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method.



Solution 1:[1]

I believe that the callable is wrapped in a runnable when it is enqueued. Callables are definitely enqueue the same as runnables when all the workers are busy.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AlexAlbu