This topic created in 1645 days ago, the information mentioned may be changed or developed.
如果保证队列中一直有数据,不会阻塞 take ,取出数据就不做任何处理,丢弃,然后取下一个。这个时候其他线程对他发起中断,那么这个消费线程会抛出中断异常吗?
就是说 take 非阻塞状态为是否会抛出中断异常?
2 replies • 2022-05-11 16:54:46 +08:00
 |
|
不知道我有没有理解错问题...看了下 LinkedBlockingQueue 和 ArrayBlockingQueue 中的 take 方法(其他没看),无论是否有元素都会先调用 ReentrantLock 的 lockInterruptibly 方法(实际在 AQS 中),而这个方法在线程中断时就会抛出中断异常,根本不会走到 await 。
|