/** * Resets the counter to zero. But waiting threads won't be released somehow. So this interrupts * the threads so that they escape from their waiting state. */ public void resetAndInterrupt() { sync.reset(); for (int i = 0; i < 3; i++) // Because it is a best effort thing, do it three times and hope for the best. for (Thread t : sync.getQueuedThreads()) t.interrupt(); sync.reset(); // Just in case a thread would've incremented the counter again. }
/** Provide access to the list of threads waiting to acquire this limited shared latch. */ public Collection<Thread> getQueuedThreads() { return sync.getQueuedThreads(); }
/** * Returns a collection containing threads that may be waiting to acquire this lock. Because the * actual set of threads may change dynamically while constructing this result, the returned * collection is only a best-effort estimate. The elements of the returned collection are in no * particular order. This method is designed to facilitate construction of subclasses that provide * more extensive monitoring facilities. * * @return the collection of threads */ protected Collection getQueuedThreads() { return sync.getQueuedThreads(); }