zoukankan      html  css  js  c++  java
  • BlockingQueue 原理 分析

    ReentrantLock 两个两个比较大的特性。
    1.中断
    2.定时
    3.公平锁。

    ReadWriteLock

    读读不互斥
    读写互斥
    写写互斥。
    Condition 类似于 Object.wait()和Object.notify()和synchronized配套使用

    CountDownLatch lanchi
    synchronized

    static final CountDownLatch end = new CountDownLatch(10);
    end.countDown();
    end.await();

    CyclicBarrier 循环栅栏 CountDownLatch可以循环使用。

    Semaphore
    共享锁
    运行多个线程同时临界区

    ArrayBlockingQueue

    ReentrantLock
    +两个Condition

    /** Main lock guarding all access */
    final ReentrantLock lock;
    /** Condition for waiting takes */
    private final Condition notEmpty;
    /** Condition for waiting puts */
    private final Condition notFull;


    offer
    take
    当写入时。判断锁unlock 判断条件
    是否已经满了,如果慢了 等等 未满Condition的通知条件。

    调用insert 插入 然后notEmpty


    BlockingQueue


    public void put(E e) throws InterruptedException {
    checkNotNull(e);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
    while (count == items.length)
    notFull.await();
    insert(e);
    } finally {
    lock.unlock();
    }
    }


    private void insert(E x) {
    items[putIndex] = x;
    putIndex = inc(putIndex);
    ++count;
    notEmpty.signal();
    }

  • 相关阅读:
    py-day2-4 python 集合
    LR_问题_控制器不能使用定义的负载生成器
    LR_问题_无法使用LR的Controller,提示缺少license
    LR_问题_在导入wsdl时出现parsing error
    class, extends和super es6语法
    格式化日期
    CLR
    【sqlserver】批量插入10万数据
    php正则表达式匹配函数
    css overflow
  • 原文地址:https://www.cnblogs.com/itxuexiwang/p/6270323.html
Copyright © 2011-2022 走看看