04 2021 档案
摘要:// 尝试获取锁 // 尝试获取成功返回true // 尝试获取失败返回false final boolean tryLock() { Thread current = Thread.currentThread(); int c = getState(); // c == 0 说明当前锁处于闲置状态
阅读全文
摘要:/** * Unlinks the given node and other non-waiting nodes from * condition queue unless already unlinked. */ private void unlinkCancelledWaiters(Condit
阅读全文
摘要:/** * Removes and transfers one or all waiters to sync queue. */ private void doSignal(ConditionNode first, boolean all) { while (first != null) { Con
阅读全文
摘要:public final void await() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); ConditionNode node = new Condition
阅读全文
摘要:// 函数作用: // 1.设定node的各项参数 // 2.将node加入ConditionNode等待队列 // 3.释放当前线程持有的锁 private int enableWait(ConditionNode node) { if (isHeldExclusively()) { // nod
阅读全文
摘要:public final boolean release(int arg) { if (tryRelease(arg)) { // 注意,这里signalNext的参数为head,即头结点 // 也就是说线程释放锁后总是会激活等待队列中的第一个节点 signalNext(head); return
阅读全文
摘要:public final boolean tryAcquireNanos(int arg, long nanosTimeout) throws InterruptedException { // 如果线程已经被中断则抛中断异常 if (!Thread.interrupted()) { // 首次简单
阅读全文
摘要:此处的acquire方法指AQS内部的私有acquire方法,方法签名为 final int acquire(Node node, int arg, boolean shared, boolean interruptible, boolean timed, long time) static fin
阅读全文
摘要:该文章对Integer类源代码中的重点、难点代码段进行分析。对于源代码中比较简单的部分不再赘述,有需要的可以直接查看源代码。 Integer::stringSize(int x) 计算一个int类型的数值转换成字符串后长度为多少 1 static int stringSize(int x) { 2
阅读全文
摘要:// interruptible 为true表示当线程的interrupted标识位被置位时 // 返回一个负数;为false表示不返回一个负数,并重新置位一次interrupted标志位 private int cancelAcquire(Node node, boolean interrupte
阅读全文

浙公网安备 33010602011771号