本文整理汇总了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();
}
}
示例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();
}
}
示例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) {}
}
示例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) {}
}
示例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) {}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}