当前位置: 首页>>代码示例>>Java>>正文


Java ReentrantLock.hasWaiters方法代码示例

本文整理汇总了Java中java.util.concurrent.locks.ReentrantLock.hasWaiters方法的典型用法代码示例。如果您正苦于以下问题:Java ReentrantLock.hasWaiters方法的具体用法?Java ReentrantLock.hasWaiters怎么用?Java ReentrantLock.hasWaiters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.locks.ReentrantLock的用法示例。


在下文中一共展示了ReentrantLock.hasWaiters方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clear

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
    final Object[] items = this.items;
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        int k = count;
        if (k > 0) {
            final int putIndex = this.putIndex;
            int i = takeIndex;
            do {
                items[i] = null;
                if (++i == items.length)
                    i = 0;
            } while (i != putIndex);
            takeIndex = putIndex;
            count = 0;
            if (itrs != null)
                itrs.queueIsEmpty();
            for (; k > 0 && lock.hasWaiters(notFull); k--)
                notFull.signal();
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:roger-dv,项目名称:spartan-jasync,代码行数:30,代码来源:ArrayBlockingQueue.java

示例2: clear

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * Atomically removes all of the elements from this queue.
 * The queue will be empty after this call returns.
 */
public void clear() {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        int k;
        if ((k = count) > 0) {
            circularClear(items, takeIndex, putIndex);
            takeIndex = putIndex;
            count = 0;
            if (itrs != null)
                itrs.queueIsEmpty();
            for (; k > 0 && lock.hasWaiters(notFull); k--)
                notFull.signal();
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ArrayBlockingQueue.java

示例3: testHasWaitersNPE

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testHasWaitersNPE(boolean fair) {
    final ReentrantLock lock = new ReentrantLock(fair);
    try {
        lock.hasWaiters(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ReentrantLockTest.java

示例4: testHasWaitersIAE

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testHasWaitersIAE(boolean fair) {
    final ReentrantLock lock = new ReentrantLock(fair);
    final Condition c = lock.newCondition();
    final ReentrantLock lock2 = new ReentrantLock(fair);
    try {
        lock2.hasWaiters(c);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ReentrantLockTest.java

示例5: testHasWaitersIMSE

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testHasWaitersIMSE(boolean fair) {
    final ReentrantLock lock = new ReentrantLock(fair);
    final Condition c = lock.newCondition();
    try {
        lock.hasWaiters(c);
        shouldThrow();
    } catch (IllegalMonitorStateException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ReentrantLockTest.java

示例6: hasWaiters

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
static boolean hasWaiters(ReentrantLock lock, Condition condition) {
    lock.lock();
    try {
        return lock.hasWaiters(condition);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ZeroCoreThreads.java

示例7: drainTo

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws ClassCastException            {@inheritDoc}
 * @throws NullPointerException          {@inheritDoc}
 * @throws IllegalArgumentException      {@inheritDoc}
 */
public int drainTo(Collection<? super E> c, int maxElements) {
    checkNotNull(c);
    if (c == this)
        throw new IllegalArgumentException();
    if (maxElements <= 0)
        return 0;
    final Object[] items = this.items;
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        int n = Math.min(maxElements, count);
        int take = takeIndex;
        int i = 0;
        try {
            while (i < n) {
                @SuppressWarnings("unchecked")
                E x = (E) items[take];
                c.add(x);
                items[take] = null;
                if (++take == items.length)
                    take = 0;
                i++;
            }
            return n;
        } finally {
            // Restore invariants even if c.add() threw
            if (i > 0) {
                count -= i;
                takeIndex = take;
                if (itrs != null) {
                    if (count == 0)
                        itrs.queueIsEmpty();
                    else if (i > take)
                        itrs.takeIndexWrapped();
                }
                for (; i > 0 && lock.hasWaiters(notFull); i--)
                    notFull.signal();
            }
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:roger-dv,项目名称:spartan-jasync,代码行数:50,代码来源:ArrayBlockingQueue.java

示例8: drainTo

import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws ClassCastException            {@inheritDoc}
 * @throws NullPointerException          {@inheritDoc}
 * @throws IllegalArgumentException      {@inheritDoc}
 */
public int drainTo(Collection<? super E> c, int maxElements) {
    Objects.requireNonNull(c);
    if (c == this)
        throw new IllegalArgumentException();
    if (maxElements <= 0)
        return 0;
    final Object[] items = this.items;
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        int n = Math.min(maxElements, count);
        int take = takeIndex;
        int i = 0;
        try {
            while (i < n) {
                @SuppressWarnings("unchecked")
                E e = (E) items[take];
                c.add(e);
                items[take] = null;
                if (++take == items.length) take = 0;
                i++;
            }
            return n;
        } finally {
            // Restore invariants even if c.add() threw
            if (i > 0) {
                count -= i;
                takeIndex = take;
                if (itrs != null) {
                    if (count == 0)
                        itrs.queueIsEmpty();
                    else if (i > take)
                        itrs.takeIndexWrapped();
                }
                for (; i > 0 && lock.hasWaiters(notFull); i--)
                    notFull.signal();
            }
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:ArrayBlockingQueue.java


注:本文中的java.util.concurrent.locks.ReentrantLock.hasWaiters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。