Refine search
BlockingFlowableIterator(int batchSize) { this.queue = new SpscArrayQueue<T>(batchSize); this.batchSize = batchSize; this.limit = batchSize - (batchSize >> 2); this.lock = new ReentrantLock(); this.condition = lock.newCondition(); }
private Lock lock = new ReentrantLock(); private Condition notFull = lock.newCondition(); private Condition notEmpty = lock.newCondition(); lock.lock(); try { while(queue.size() == capacity) { notEmpty.signal(); } finally { lock.unlock(); lock.lock(); try { while(queue.isEmpty()) { return item; } finally { lock.unlock();
InternalCompletionListenerForTest getInternalCompletionListenerForTest(String requestId) throws InterruptedException { iclCreationLock.lock(); try { Condition condition = iclCreationConditions.get(requestId); if (condition == null) { condition = iclCreationLock.newCondition(); iclCreationConditions.put(requestId, condition); } while (completionListeners.get(requestId) == null) { condition.await(); } return completionListeners.get(requestId); } finally { iclCreationLock.unlock(); } }
@Test public void acquireCleanJobLock_returns_a_non_current_lock() { StandaloneCeDistributedInformation underTest = new StandaloneCeDistributedInformation(mock(CeWorkerFactory.class)); Lock lock = underTest.acquireCleanJobLock(); IntStream.range(0, 5 + Math.abs(new Random().nextInt(50))) .forEach(i -> { try { assertThat(lock.tryLock()).isTrue(); assertThat(lock.tryLock(1, TimeUnit.MINUTES)).isTrue(); lock.lock(); lock.lockInterruptibly(); lock.unlock(); } catch (InterruptedException e) { fail("no InterruptedException should be thrown"); } try { lock.newCondition(); fail("a UnsupportedOperationException should have been thrown"); } catch (UnsupportedOperationException e) { assertThat(e.getMessage()).isEqualTo("newCondition not supported"); } }); } }
@Override public boolean tryLock() { if (inner.tryLock()) { try { if (condition == null) { condition = inner.newCondition(); return true; } } finally { inner.unlock(); } } return false; }
/** * <p>Constructor for SimpleCondition.</p> */ public SimpleCondition() { this.lock = new ReentrantLock(); this.condition = this.lock.newCondition(); this.lock.lock(); }
@Override public void lockInterruptibly() throws InterruptedException { inner.lockInterruptibly(); try { if (condition == null) { condition = inner.newCondition(); } else { condition.await(); } } finally { inner.unlock(); } }
private final Lock lock = new ReentrantLock(); private final Condition isEmpty = lock.newCondition(); private final Condition isFull = lock.newCondition(); lock.lock(); try { while(!usedData) {//wait for data to be used lock.unlock();//interrupt or not, release lock lock.lock(); try { while(usedData) {//usedData is lingo for empty lock.unlock();
@Override InternalCompletionListener createInternalCompletionListener(TaskWrapper taskWrapper) { iclCreationLock.lock(); try { InternalCompletionListenerForTest icl = new InternalCompletionListenerForTest(taskWrapper); completionListeners.put(taskWrapper.getRequestId(), icl); Condition condition = iclCreationConditions.get(taskWrapper.getRequestId()); if (condition == null) { condition = iclCreationLock.newCondition(); iclCreationConditions.put(taskWrapper.getRequestId(), condition); } condition.signalAll(); return icl; } finally { iclCreationLock.unlock(); } }
BlockingObservableIterator(int batchSize) { this.queue = new SpscLinkedArrayQueue<T>(batchSize); this.lock = new ReentrantLock(); this.condition = lock.newCondition(); }
@Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { long deadline = System.currentTimeMillis() + unit.toMillis(time); if (inner.tryLock(time, unit)) { try { while (condition != null) { long now = System.currentTimeMillis(); if (now >= deadline) { return false; } condition.await(deadline - now, TimeUnit.MILLISECONDS); return true; } condition = inner.newCondition(); } finally { inner.unlock(); } } return false; }
/** * {@inheritDoc} * * This method creates an async call to the server, and blocks until the server * has finished annotating the object. */ @Override public void annotate(Annotation annotation) { final Lock lock = new ReentrantLock(); final Condition annotationDone = lock.newCondition(); annotate(Collections.singleton(annotation), 1, (Annotation annInput) -> { try { lock.lock(); annotationDone.signal(); } finally { lock.unlock(); } }); try { lock.lock(); annotationDone.await(); // Only wait for one callback to complete; only annotating one document } catch (InterruptedException e) { log.info("Interrupt while waiting for annotation to return"); } finally { lock.unlock(); } }
poolLock.lock(); try { newWaitingThread(poolLock.newCondition(), rospl); aborter.setWaitingThread(waitingThread); poolLock.unlock();
public CondVar() { lock=new ReentrantLock(); cond=lock.newCondition(); }
@ExpectWarning("RV") public static void main(String args[]) throws Exception { String str = " ttesting "; str.trim(); str.toLowerCase(); str.toUpperCase(); str.replace(" ", ""); str.replace(' ', '.'); str.substring(0, 10); str.equals("testing"); Semaphore s = new Semaphore(17, true); s.tryAcquire(); s.tryAcquire(12, TimeUnit.MILLISECONDS); BlockingQueue<Object> q = new LinkedBlockingQueue<Object>(); q.offer(new Object()); q.offer(new Object(), 12, TimeUnit.MILLISECONDS); q.poll(12, TimeUnit.MILLISECONDS); q.poll(); Lock l = new ReentrantLock(); Condition c = l.newCondition(); l.lock(); try { c.awaitNanos(12); c.awaitUntil(new Date()); c.await(12, TimeUnit.NANOSECONDS); } finally { l.unlock(); } q.poll(); }
@Override public synchronized void lock() { inner.lock(); try { if (condition == null) { condition = inner.newCondition(); } else { condition.awaitUninterruptibly(); } } finally { inner.unlock(); } }
public RpcContent(int seconds) { this.seconds = seconds; lock = new ReentrantLock(true); condition = lock.newCondition(); }
public static void waitUntilOtherEntityIsSubscribed(Roster roster, final BareJid otherEntity, Date deadline) throws InterruptedException, TimeoutException { final Lock lock = new ReentrantLock(); final Condition maybeSubscribed = lock.newCondition(); RosterListener rosterListener = new AbstractRosterListener() { private void signal() { lock.lock(); try { while (!roster.isSubscribedToMyPresence(otherEntity)) { lock.unlock();
public BlockTask() { lock = new ReentrantLock(); condition = lock.newCondition(); notify = false; remove = false; }
AtomicInteger callbacksReceived = new AtomicInteger(0); AtomicInteger callbacksExpected = new AtomicInteger(0); final Lock lock = new ReentrantLock(); final Condition condition = lock.newCondition(); if (incrementBuffer != null) { incrementBuffer.clear(); lock.lock(); long startTime = System.nanoTime(); long timeRemaining; lock.unlock();