简体   繁体   中英

Interrupt all waiting threads with Reentrant lock Java

Is there any way in which I could interrupt all the threads that are waiting for lock if the thread which already acquired lock has some exception?

I don't think there is a good way.

If you created a subclass of ReentrantLock , that class could call getQueuedThreads() , iterate the resulting collection and call interrupt() on each one. However, that is liable to be fraught with race conditions. For example, if another thread attempts to acquire the lock while you are doing this, there is no guarantee that you will see that thread.

The second problem is figuring where and by what the exception would be detected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM