Class HackedBlockingQueue<E>

All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

public class HackedBlockingQueue<E> extends LinkedBlockingQueue<E>

Tricks the behaviour of LinkedBlockingQueue so that methods like offer(Object) and poll() actually invoke LinkedBlockingQueue.put(Object) and LinkedBlockingQueue.take(), i.e., the queue always waits for itself to be free-of/filled-with-some value/s.

This can be used in ThreadPoolExecutor, which of AbstractExecutorService.submit(Runnable) methods can raise RejectedExecutionException by calling offer(). By passing this class to its constructor, the executor will always wait for a free thread, either in the executor or in the task queue.

Credits.

Author:
brandizi
Date:
22 Dec 2017
See Also: