阻塞队列

  1. 和队列的offer和poll不同
    阻塞队列是put和take
  2. 和list同级
  3. 常用的三个:array,list(默认是int.max)和synchronous(这个不存元素,只有单个)

停摆之前操作

只能在take之前去操作 不然就完蛋
如果第二个take写在新线程之前,自己的两个打印都会卡住

class XXX{
    static BlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<Integer>(3);
    public static void main(String[] args) throws InterruptedException {
        blockingQueue.put(1);
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        new Thread(()->{
            try {
                Thread.sleep(100);
                blockingQueue.put(2121);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
//        1
//        新开线程操作
//        添加完成
//        2121
}
原文地址:https://www.cnblogs.com/purexww/p/15249904.html