/** * Factory method to change a lock */ protected Lock createLock(String id) { return new ReentrantLock(); } }
/** * Factory method to change a lock */ protected Lock createLock(String id) { return new ReentrantLock(); } }
/** * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed) * capacity and the specified access policy. * @param capacity the capacity of this queue * @param fair if <tt>true</tt> then queue accesses for threads blocked * on insertion or removal, are processed in FIFO order; * if <tt>false</tt> the access order is unspecified. * @throws IllegalArgumentException if <tt>capacity</tt> is less than 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(); }
/** * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed) * capacity and the specified access policy. * @param capacity the capacity of this queue * @param fair if <tt>true</tt> then queue accesses for threads blocked * on insertion or removal, are processed in FIFO order; * if <tt>false</tt> the access order is unspecified. * @throws IllegalArgumentException if <tt>capacity</tt> is less than 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(); }
/** * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed) * capacity and the specified access policy. * @param capacity the capacity of this queue * @param fair if <tt>true</tt> then queue accesses for threads blocked * on insertion or removal, are processed in FIFO order; * if <tt>false</tt> the access order is unspecified. * @throws IllegalArgumentException if <tt>capacity</tt> is less than 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(); }
/** * Creates a <tt>SynchronousQueue</tt> with specified fairness policy. * @param fair if true, threads contend in FIFO order for access; * otherwise the order is unspecified. */ public SynchronousQueue(boolean fair) { if (fair) { qlock = new ReentrantLock(true); waitingProducers = new FifoWaitQueue(); waitingConsumers = new FifoWaitQueue(); } else { qlock = new ReentrantLock(); waitingProducers = new LifoWaitQueue(); waitingConsumers = new LifoWaitQueue(); } }
/** * Returns an internal ReentrantLock object, shared between all instances * of ReentrantNamedLock with the same name. (Name identity is defined * in terms of the equals() method). * A static instance of WeakValueHashMap is used to keep track of the * (name,resolved lock) pairs. * * @param name name of the named lock * @return an interned reentrant lock */ synchronized static ReentrantLock getLockFor(Object name) { ReentrantLock lock = (ReentrantLock)lockResolver.get(name); if (lock == null) { lock = new ReentrantLock(); lockResolver.put(name, lock); } return lock; }
/** * Creates a <tt>SynchronousQueue</tt> with specified fairness policy. * @param fair if true, threads contend in FIFO order for access; * otherwise the order is unspecified. */ public SynchronousQueue(boolean fair) { if (fair) { qlock = new ReentrantLock(true); waitingProducers = new FifoWaitQueue(); waitingConsumers = new FifoWaitQueue(); } else { qlock = new ReentrantLock(); waitingProducers = new LifoWaitQueue(); waitingConsumers = new LifoWaitQueue(); } }
/** * Creates a <tt>SynchronousQueue</tt> with specified fairness policy. * @param fair if true, threads contend in FIFO order for access; * otherwise the order is unspecified. */ public SynchronousQueue(boolean fair) { if (fair) { qlock = new ReentrantLock(true); waitingProducers = new FifoWaitQueue(); waitingConsumers = new FifoWaitQueue(); } else { qlock = new ReentrantLock(); waitingProducers = new LifoWaitQueue(); waitingConsumers = new LifoWaitQueue(); } }