本文整理了Java中java.util.concurrent.locks.ReentrantLock.newCondition
方法的一些代码示例,展示了ReentrantLock.newCondition
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReentrantLock.newCondition
方法的具体详情如下:
包路径:java.util.concurrent.locks.ReentrantLock
类名称:ReentrantLock
方法名:newCondition
[英]Returns a Condition instance for use with this Lock instance.
The returned Condition instance supports the same usages as do the Object monitor methods ( Object#wait(), Object#notify, and Object#notifyAll) when used with the built-in monitor lock.
代码示例来源:origin: alibaba/druid
public DruidAbstractDataSource(boolean lockFair){
lock = new ReentrantLock(lockFair);
notEmpty = lock.newCondition();
empty = lock.newCondition();
}
代码示例来源:origin: apache/flink
/**
* Creates a new empty queue, reserving space for at least the specified number
* of elements. The queue can still grow, of more elements are added than the
* reserved space.
*
* @param initialSize The number of elements to reserve space for.
*/
public ClosableBlockingQueue(int initialSize) {
this.lock = new ReentrantLock(true);
this.nonEmpty = this.lock.newCondition();
this.elements = new ArrayDeque<>(initialSize);
this.open = true;
}
代码示例来源:origin: alibaba/cobar
public BufferQueue(int capacity) {
items = new ByteBuffer[capacity];
lock = new ReentrantLock();
notFull = lock.newCondition();
}
代码示例来源:origin: MovingBlocks/Terasology
public DynamicPriorityBlockingQueue(Comparator<T> comparator) {
this.comparator = comparator;
lock = new ReentrantLock();
notEmpty = lock.newCondition();
}
代码示例来源:origin: igniterealtime/Smack
@SuppressWarnings("unchecked")
public ArrayBlockingQueueWithShutdown(int capacity, boolean fair) {
if (capacity <= 0)
throw new IllegalArgumentException();
items = (E[]) new Object[capacity];
lock = new ReentrantLock(fair);
notEmpty = lock.newCondition();
notFull = lock.newCondition();
}
代码示例来源:origin: apache/incubator-druid
public DefaultBlockingPool(
Supplier<T> generator,
int limit
)
{
this.objects = new ArrayDeque<>(limit);
this.maxSize = limit;
for (int i = 0; i < limit; i++) {
objects.add(generator.get());
}
this.lock = new ReentrantLock();
this.notEnough = lock.newCondition();
}
代码示例来源:origin: Alluxio/alluxio
/**
* Internal constructor that can provide an object to be used for the internal queue.
*
* @param maxCapacity bhe maximum of resources in this pool
* @param resources blocking queue to use
*/
protected ResourcePool(int maxCapacity, ConcurrentLinkedQueue<T> resources) {
mTakeLock = new ReentrantLock();
mNotEmpty = mTakeLock.newCondition();
mMaxCapacity = maxCapacity;
mCurrentCapacity = new AtomicInteger();
mResources = resources;
}
代码示例来源:origin: alibaba/druid
public void setUseUnfairLock(boolean useUnfairLock) {
if (lock.isFair() == !useUnfairLock) {
return;
}
if (!this.inited) {
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (!this.inited) {
this.lock = new ReentrantLock(!useUnfairLock);
this.notEmpty = this.lock.newCondition();
this.empty = this.lock.newCondition();
this.useUnfairLock = useUnfairLock;
}
} finally {
lock.unlock();
}
}
}
代码示例来源:origin: robovm/robovm
/**
* Creates an {@code ArrayBlockingQueue} with the given (fixed)
* capacity and the specified access policy.
*
* @param capacity the capacity of this queue
* @param fair if {@code true} then queue accesses for threads blocked
* on insertion or removal, are processed in FIFO order;
* if {@code false} the access order is unspecified.
* @throws IllegalArgumentException if {@code capacity < 1}
*/
public ArrayBlockingQueue(int capacity, boolean fair) {
if (capacity <= 0)
throw new IllegalArgumentException();
this.items = new Object[capacity];
lock = new ReentrantLock(fair);
notEmpty = lock.newCondition();
notFull = lock.newCondition();
}
代码示例来源:origin: apache/ignite
/**
* @param concLvl Concurrency level, must be a power of two.
*/
public OffheapReadWriteLock(int concLvl) {
if ((concLvl & concLvl - 1) != 0)
throw new IllegalArgumentException("Concurrency level must be a power of 2: " + concLvl);
monitorsMask = concLvl - 1;
locks = new ReentrantLock[concLvl];
readConditions = new Condition[concLvl];
writeConditions = new Condition[concLvl];
balancers = new AtomicInteger[concLvl];
for (int i = 0; i < locks.length; i++) {
ReentrantLock lock = new ReentrantLock();
locks[i] = lock;
readConditions[i] = lock.newCondition();
writeConditions[i] = lock.newCondition();
balancers[i] = new AtomicInteger(0);
}
}
代码示例来源:origin: alibaba/druid
public void setMaxWait(long maxWaitMillis) {
if (maxWaitMillis == this.maxWait) {
return;
}
if (maxWaitMillis > 0 && useUnfairLock == null && !this.inited) {
final ReentrantLock lock = this.lock;
lock.lock();
try {
if ((!this.inited) && (!lock.isFair())) {
this.lock = new ReentrantLock(true);
this.notEmpty = this.lock.newCondition();
this.empty = this.lock.newCondition();
}
} finally {
lock.unlock();
}
}
if (inited) {
LOG.error("maxWait changed : " + this.maxWait + " -> " + maxWaitMillis);
}
this.maxWait = maxWaitMillis;
}
代码示例来源:origin: apache/flink
public OrderedStreamElementQueue(
int capacity,
Executor executor,
OperatorActions operatorActions) {
Preconditions.checkArgument(capacity > 0, "The capacity must be larger than 0.");
this.capacity = capacity;
this.executor = Preconditions.checkNotNull(executor, "executor");
this.operatorActions = Preconditions.checkNotNull(operatorActions, "operatorActions");
this.lock = new ReentrantLock(false);
this.headIsCompleted = lock.newCondition();
this.notFull = lock.newCondition();
this.queue = new ArrayDeque<>(capacity);
}
代码示例来源:origin: robovm/robovm
/**
* Creates a {@code PriorityBlockingQueue} with the specified initial
* capacity that orders its elements according to the specified
* comparator.
*
* @param initialCapacity the initial capacity for this priority queue
* @param comparator the comparator that will be used to order this
* priority queue. If {@code null}, the {@linkplain Comparable
* natural ordering} of the elements will be used.
* @throws IllegalArgumentException if {@code initialCapacity} is less
* than 1
*/
public PriorityBlockingQueue(int initialCapacity,
Comparator<? super E> comparator) {
if (initialCapacity < 1)
throw new IllegalArgumentException();
this.lock = new ReentrantLock();
this.notEmpty = lock.newCondition();
this.comparator = comparator;
this.queue = new Object[initialCapacity];
}
代码示例来源:origin: apache/flink
public UnorderedStreamElementQueue(
int capacity,
Executor executor,
OperatorActions operatorActions) {
Preconditions.checkArgument(capacity > 0, "The capacity must be larger than 0.");
this.capacity = capacity;
this.executor = Preconditions.checkNotNull(executor, "executor");
this.operatorActions = Preconditions.checkNotNull(operatorActions, "operatorActions");
this.uncompletedQueue = new ArrayDeque<>(capacity);
this.completedQueue = new ArrayDeque<>(capacity);
this.firstSet = new HashSet<>(capacity);
this.lastSet = firstSet;
this.numberEntries = 0;
this.lock = new ReentrantLock();
this.notFull = lock.newCondition();
this.hasCompletedEntries = lock.newCondition();
}
代码示例来源:origin: spotbugs/spotbugs
public static void main(String args[]) throws Exception {
ReentrantLock lock1 = new ReentrantLock();
ReadWriteLock rwLock = new ReentrantReadWriteLock();
Lock lock2 = rwLock.readLock();
Lock lock3 = rwLock.writeLock();
rwLock.readLock();
lock1.newCondition();
lock2.newCondition();
lock1.tryLock();
lock2.tryLock();
lock3.tryLock();
synchronized (lock1) {
System.out.println("Howdy");
}
}
}
代码示例来源:origin: hierynomus/sshj
/**
* Creates this promise with given {@code name}, exception {@code chainer}, and associated {@code lock}.
*
* @param name name of this promise
* @param chainer {@link ExceptionChainer} that will be used for chaining exceptions
* @param lock lock to use
*/
public Promise(String name, ExceptionChainer<T> chainer, ReentrantLock lock, LoggerFactory loggerFactory) {
this.name = name;
this.chainer = chainer;
this.lock = lock == null ? new ReentrantLock() : lock;
this.log = loggerFactory.getLogger(getClass());
this.cond = this.lock.newCondition();
}
代码示例来源:origin: ninjaframework/ninja
public DelayedRestartTrigger(
RunClassInSeparateJvmMachine runClassInSeparateJvmMachine) {
this.shutdown = false;
this.setDaemon(true);
this.setName("DelayedRestartTrigger");
this.restartCount = new AtomicInteger(0);
this.accumulatedTriggerCount = new AtomicInteger(0);
this.restartLock = new ReentrantLock();
this.restartRequested = this.restartLock.newCondition();
this.runClassInSeparateJvmMachine = runClassInSeparateJvmMachine;
}
代码示例来源:origin: robovm/robovm
this.lock = new ReentrantLock();
this.notEmpty = lock.newCondition();
boolean heapify = true; // true if not known to be in heap order
boolean screen = true; // true if must screen for nulls
代码示例来源:origin: stackoverflow.com
private final ReentrantLock lock = new ReentrantLock();
private final Condition tryAgain = lock.newCondition();
private volatile boolean finished = false;
代码示例来源:origin: fengjiachun/Jupiter
private final ReentrantLock lock = new ReentrantLock();
private final Condition notifyCondition = lock.newCondition();
内容来源于网络,如有侵权,请联系作者删除!