[英]Blocking queue is not blocking the thread?
我在程序中使用阻塞队列..我的客户端请求轮询响应,服务器请求响应给队列。我没有使用客户端的任何thread.sleep机制,因为我使用blockingqueue ..但是我从队列,当我的服务器线程延迟将一些消息放入队列时。为什么会发生这种情况? 我的代码;
private BlockingQueue<Message> applicationResponses= new LinkedBlockingQueue<Message>();
client
--------
Message response = applicationResponses.poll();
server;
applicationResponses.offer(message);
使用take
代替poll
- take
将阻塞线程,直到对象准备就绪,而如果队列为空,则poll
将仅返回null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.