zoukankan      html  css  js  c++  java
  • 阻塞队列

    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
    }
    
  • 相关阅读:
    Python保留最后N个元素
    STL算法
    STL迭代器
    STL容器
    C++总结1
    牛客剑指Offer2
    Vue第一天
    UML
    Java继承和组合代码
    Java15后的sealed阻止继承滥用
  • 原文地址:https://www.cnblogs.com/purexww/p/15249904.html
Copyright © 2011-2022 走看看