/** * Instantiates a LimitLatch object with an initial limit. * @param limit - maximum number of concurrent acquisitions of this latch */ public LimitLatch(long limit) { this.limit = limit; this.count = new AtomicLong(0); this.sync = new Sync(); }
/** * Acquires a shared latch if one is available or waits for one if no shared * latch is current available. */ public void countUpOrAwait() throws InterruptedException { if (log.isDebugEnabled()) { log.debug("Counting up["+Thread.currentThread().getName()+"] latch="+getCount()); } sync.acquireSharedInterruptibly(1); }
/** * Releases a shared latch, making it available for another thread to use. * @return the previous counter value */ public long countDown() { sync.releaseShared(0); long result = getCount(); if (log.isDebugEnabled()) { log.debug("Counting down["+Thread.currentThread().getName()+"] latch="+result); } return result; }
/** * Releases all waiting threads and causes the {@link #limit} to be ignored * until {@link #reset()} is called. * @return <code>true</code> if release was done */ public boolean releaseAll() { released = true; return sync.releaseShared(0); }
/** * Returns <code>true</code> if there is at least one thread waiting to * acquire the shared lock, otherwise returns <code>false</code>. * @return <code>true</code> if threads are waiting */ public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
/** * Releases all waiting threads and causes the {@link #limit} to be ignored * until {@link #reset()} is called. */ public boolean releaseAll() { released = true; return sync.releaseShared(0); }
/** * Releases a shared latch, making it available for another thread to use. * @return the previous counter value */ public long countDown() { sync.releaseShared(0); long result = getCount(); if (log.isDebugEnabled()) { log.debug("Counting down["+Thread.currentThread().getName()+"] latch="+result); } return result; }
/** * Provide access to the list of threads waiting to acquire this limited * shared latch. */ public Collection<Thread> getQueuedThreads() { return sync.getQueuedThreads(); } }
/** * Releases a shared latch, making it available for another thread to use. * @return the previous counter value */ public long countDown() { sync.releaseShared(0); return count.get(); }
/** * Acquires a shared latch if one is available or waits for one if no shared * latch is current available. */ public void countUpOrAwait() throws InterruptedException { sync.acquireSharedInterruptibly(1); }
/** * Provide access to the list of threads waiting to acquire this limited * shared latch. * @return a collection of threads */ public Collection<Thread> getQueuedThreads() { return sync.getQueuedThreads(); } }
/** * Instantiates a LimitLatch object with an initial limit. * @param limit - maximum number of concurrent acquisitions of this latch */ public LimitLatch(long limit) { this.limit = limit; this.count = new AtomicLong(0); this.sync = new Sync(); }
/** * Releases all waiting threads and causes the {@link #limit} to be ignored * until {@link #reset()} is called. */ public boolean releaseAll() { released = true; return sync.releaseShared(0); }
/** * Releases all waiting threads and causes the {@link #limit} to be ignored * until {@link #reset()} is called. */ public boolean releaseAll() { released = true; return sync.releaseShared(0); }
/** * Returns <code>true</code> if there is at least one thread waiting to * acquire the shared lock, otherwise returns <code>false</code>. */ public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
/** * Acquires a shared latch if one is available or waits for one if no shared * latch is current available. * @throws InterruptedException If the current thread is interrupted */ public void countUpOrAwait() throws InterruptedException { if (log.isDebugEnabled()) { log.debug("Counting up["+Thread.currentThread().getName()+"] latch="+getCount()); } sync.acquireSharedInterruptibly(1); }
/** * Releases a shared latch, making it available for another thread to use. * @return the previous counter value */ public long countDown() { sync.releaseShared(0); long result = getCount(); if (log.isDebugEnabled()) { log.debug("Counting down["+Thread.currentThread().getName()+"] latch="+result); } return result; }
/** * Instantiates a LimitLatch object with an initial limit. * @param limit - maximum number of concurrent acquisitions of this latch */ public LimitLatch(long limit) { this.limit = limit; this.count = new AtomicLong(0); this.sync = new Sync(); }
/** * Instantiates a LimitLatch object with an initial limit. * @param limit - maximum number of concurrent acquisitions of this latch */ public LimitLatch(long limit) { this.limit = limit; this.count = new AtomicLong(0); this.sync = new Sync(); }
/** * Provide access to the list of threads waiting to acquire this limited * shared latch. */ public Collection<Thread> getQueuedThreads() { return sync.getQueuedThreads(); } }