Refine search
public DruidAbstractDataSource(boolean lockFair){ lock = new ReentrantLock(lockFair); notEmpty = lock.newCondition(); empty = lock.newCondition(); }
/** * 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; }
public BufferQueue(int capacity) { items = new ByteBuffer[capacity]; lock = new ReentrantLock(); notFull = lock.newCondition(); }
public DynamicPriorityBlockingQueue(Comparator<T> comparator) { this.comparator = comparator; lock = new ReentrantLock(); notEmpty = lock.newCondition(); }
@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(); }
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(); }
/** * 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; }
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(); } } }
/** * 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(); }
/** * @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); } }
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; }
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); }
/** * 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]; }
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(); }
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"); } } }
/** * 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(); }
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; }
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
private final ReentrantLock lock = new ReentrantLock(); private final Condition tryAgain = lock.newCondition(); private volatile boolean finished = false;
private final ReentrantLock lock = new ReentrantLock(); private final Condition notifyCondition = lock.newCondition();