0

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);
4

1 回答 1

3

使用take而不是poll-take将阻塞线程,直到对象准备好,而poll如果队列为空,则仅返回 null

于 2013-05-01T05:16:42.367 回答