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
    }
    
  • 相关阅读:
    字符、字符串和文本处理
    接口
    泛型
    事件
    Expression表达式树 案例
    栈帧
    属性
    方法
    常量和字段
    Dynamic
  • 原文地址:https://www.cnblogs.com/purexww/p/15249904.html
Copyright © 2011-2022 走看看