문제

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