Use take
instead of poll
- take
will block the thread until an object is ready, whereas poll
will simply return null if the queue is empty
Blocking queue is not blocking the thread?
-
13-04-2022 - |
質問
im using blocking queue in my program.. where my client threds poll for response, and server thred offer the response to queue.I didnt use any thread.sleep mechanism from client end, since im using blockingqueue..But im egtting null values from the queue, when my server thread delays to put some messages in the queue.. Why this is happening? My code;
private BlockingQueue<Message> applicationResponses= new LinkedBlockingQueue<Message>();
client
--------
Message response = applicationResponses.poll();
server;
applicationResponses.offer(message);
解決
所属していません StackOverflow