AbstractQueuedSynchronizer extends AbstractOwnableSynchronizer implements java.io.Serializable { public final Collection<Thread> getQueuedThreads() { ArrayList<Thread> list = new ArrayList<Thread>(); for (Node p = tail; p != null; p = p.prev) { Thread t = p.thread; if (t != null) list.add(t); } return list; } 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 testGetQueuedThreads() { final Mutex sync = new Mutex(); Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); assertHasExclusiveQueuedThreads(sync, NO_THREADS); sync.acquire(); assertHasExclusiveQueuedThreads(sync, NO_THREADS); t1.start(); waitForQueuedThread(sync, t1); assertHasExclusiveQueuedThreads(sync, t1); assertTrue(sync.getQueuedThreads().contains(t1)); assertFalse(sync.getQueuedThreads().contains(t2)); t2.start(); waitForQueuedThread(sync, t2); assertHasExclusiveQueuedThreads(sync, t1, t2); assertTrue(sync.getQueuedThreads().contains(t1)); assertTrue(sync.getQueuedThreads().contains(t2)); t1.interrupt(); awaitTermination(t1); assertHasExclusiveQueuedThreads(sync, t2); sync.release(); awaitTermination(t2); assertHasExclusiveQueuedThreads(sync, NO_THREADS); }