4
在并发程序中将对象从BlockingQueue中取出而不碰到竞争条件的最佳方法是什么?我目前在做以下,我不相信这是最好的方法:从并发程序中的BlockingQueue获取对象的最佳方法?
BlockingQueue<Violation> vQueue;
/*
in the constructor I pass in a BlockingQueue object
full of violations that need to be processed - cut out for brevity
*/
Violation v;
while ((v = vQueue.poll(500, TimeUnit.MILLISECONDS)) != null) {
// do stuff with the violation
}
我还没有打一场比赛的条件...但是,我一点也不知道这是真正安全。