質問

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);
役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top