Reputation: 7179
I don't able to find out the benefit of why JDK used LinkedBlockingQueue over ArrayBlockingQueue in Executors.newFixedThreadPool.
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
The benefit of ArrayBlockingQueue is that its fast but the collection should be bounded and defined in the beginning, which is all applicable in newFixedThreadPool.
So, there is some benefit or extra functionality needed which couldn't be achieved by ArrayBlockingQueue.
Upvotes: 0
Views: 582
Reputation: 2048
A fixedThreadPool does not mean that the internal queue is bounded but instead only a max number of threads can be created. From the Oracle documentation : Tasks are submitted to the pool via an internal queue, which holds extra tasks whenever there are more active tasks than threads.
(see https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html)
Which leads to the conclusion that if the queue is unbounded, then a LinkedBlockingQueue is more relevant since an ArrayBlockingQueue is bounded and its size cannot change.
Upvotes: 2