AbstractQueuedSynchronizer extends AbstractOwnableSynchronizer implements java.io.Serializable { public final boolean hasWaiters(ConditionObject condition) { if (!owns(condition)) throw new IllegalArgumentException("Not owner"); return condition.hasWaiters(); } protected  AbstractQueuedSynchronizer(); final void acquire(long arg); final void acquireInterruptibly(long arg); final boolean tryAcquireNanos(long arg, long nanosTimeout); final boolean release(long arg); final void acquireShared(long arg); final void acquireSharedInterruptibly(long arg); final boolean tryAcquireSharedNanos(long arg, long nanosTimeout); final boolean releaseShared(long arg); final boolean hasQueuedThreads(); final boolean hasContended(); final Thread getFirstQueuedThread(); final boolean isQueued(Thread thread); final boolean hasQueuedPredecessors(); final int getQueueLength(); final Collection<Thread> getQueuedThreads(); final Collection<Thread> getExclusiveQueuedThreads(); final Collection<Thread> getSharedQueuedThreads(); String toString(); final boolean owns(ConditionObject condition); final boolean hasWaiters(ConditionObject condition); final int getWaitQueueLength(ConditionObject condition); final Collection<Thread> getWaitingThreads(ConditionObject condition);  }
@Test public void testHasWaitersNPE() { final Mutex sync = new Mutex(); try { sync.hasWaiters(null); shouldThrow(); } catch (NullPointerException success) {} }
@Test public void testHasWaitersIAE() { final Mutex sync = new Mutex(); final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition(); final Mutex sync2 = new Mutex(); try { sync2.hasWaiters(c); shouldThrow(); } catch (IllegalArgumentException success) {} assertHasWaitersUnlocked(sync, c, NO_THREADS); }
@Test public void testHasWaitersIMSE() { final Mutex sync = new Mutex(); final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition(); try { sync.hasWaiters(c); shouldThrow(); } catch (IllegalMonitorStateException success) {} assertHasWaitersUnlocked(sync, c, NO_THREADS); }
@Test public void testHasWaiters() { final Mutex sync = new Mutex(); final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition(); final BooleanLatch acquired = new BooleanLatch(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { sync.acquire(); assertHasWaitersLocked(sync, c, NO_THREADS); assertFalse(sync.hasWaiters(c)); assertTrue(acquired.releaseShared(0)); c.await(); sync.release(); }}); acquired.acquireShared(0); sync.acquire(); assertHasWaitersLocked(sync, c, t); assertHasExclusiveQueuedThreads(sync, NO_THREADS); assertTrue(sync.hasWaiters(c)); c.signal(); assertHasWaitersLocked(sync, c, NO_THREADS); assertHasExclusiveQueuedThreads(sync, t); assertFalse(sync.hasWaiters(c)); sync.release(); awaitTermination(t); assertHasWaitersUnlocked(sync, c, NO_THREADS); }