Under what conditions will BlockingQueue.take throw interrupted exception?
2015-03-27 13:52
288 查看
Poison Pill:A good way to signal termination of a blocking queue is to submit a 'poison' value into the queue that
indicates a shutdown has occurred. This ensures that the expected behavior of the queue is honored. Calling Thread.interupt() is probably not a good idea if you care about clearing the queue.
To provide some code:
indicates a shutdown has occurred. This ensures that the expected behavior of the queue is honored. Calling Thread.interupt() is probably not a good idea if you care about clearing the queue.
To provide some code:
boolean shutdown = false;while (!shutdown) { try { WorkItem w = inQueue.take(); if (w == QUEUE_IS_DEAD) shutdown = true; else w.consume(); } catch (InterruptedException e) { // possibly submit QUEUE_IS_DEAD to the queue }}
相关文章推荐
- Question 34: Under which of the following conditions will a C++ developer use polymorphism?
- 通过扩展 PriorityBlockingQueue 的 take() 实现任务定时触发
- 多线程之BlockingQueue中 take、offer、put、add的一些比较
- java 编程思想中的PriorityBlockingQueue 部分里对PrioritizedTask的排序没有显式调用collection的sort方法。而是通过take时做的这个动作
- LinkedBlockingQueue的put,add,offer和poll,remove,take的区别
- LinkedBlockingQueue操作,线程安全问题,ConcurrentModificationException 异常分析与解决方案
- 优先级队列PriorityBlockingQueue
- Java集合源码学习(15)_Queue接口的实现PriorityQueue和PriorityBlockingQueue
- Java并发之BlockingQueue 阻塞队列(ArrayBlockingQueue、LinkedBlockingQueue、DelayQueue、PriorityBlockingQueue、SynchronousQueue)
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue使用场景总结(待整理)
- java.util.concurrent.BlockingQueue ArrayBlockingQueue
- Concurrent包中Queue(1)----LinkedBlockingQueue
- JAVA多线程之——ArrayBlockingQueue
- JAVA多线程之——LinkedBlockingQueue
- LinkedBlockingQueue.poll方法测试(转载)
- 利用ArrayBlockingQueue实现生产者-消费者
- JAVA并发编程随笔【一】PriorityBlockingQueue优先级队列
- JAVA并发编程随笔【一】PriorityBlockingQueue优先级队列
- 多线程编程8---ArrayBlockingQueue解决子循环5次主循环10次 一次交替10次
- Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.