等待和唤醒线程
等待和唤醒线程
在Object类中
阻塞队列唤醒等待机制(视频外补充)
阻塞队列继承结构
graph LR A(Iterable 接口)-->B(Collection 接口)-->D(Queue 接口)-->E(BlockingQueue 接口)-->F(ArrayBlockingQueue 实现类) & G(LinkedBlockingQueue 实现类)
BlockingQueue的核心方法:
- put(anObject)将参数放入队列,如果放不进去会阻塞
- take(): 取出第一个数据,则不到会阻塞
常见的BlockingQueue:
- ArrayBlockingQueue: 底层是数组,有界‘
- LinkedBlockingQueue: 底层是链表,无界,但不是真正的无界,最大为int的最大值