I am using a LinkedBlockingQueue
in a multithreaded environment, where multiple threads act as consumers. Currently I am using queue.take()
to get the object from queue, which is causing the thread to wait indefinitely when queue becomes empty. To avoid this can I use queue.poll()
method with specified timeout with the following conditions :
1. all other threads are blocked for the specified timeout period except the current thread with call to poll(long timeout, TimeUnit unit)
method.
If not, is there any way I can achieve this ?
Any leads appreciated. Thanks in advance.