简体   繁体   中英

Can one thread directly make another thread wait?

In Java, is it possible for one thread to cause another thread to wait by calling wait(), or without signaling of some kind? I'm not actually trying to achieve or implement some practical end, like in the post How to synchronize shared data between threads by using pause then resume or alternatives . This is more of a theoretical exploration of whether such a thing possible in Java threading.

No, you cannot safely and reliably pause a thread using normal Java. Threads can pause themselves but not each other.

Threads do have suspend and resume methods, but as it turned out, they're not safe and can easily cause your whole program to freeze (deadlock). You really don't want to have to use them.

No. It is not possible from one thread to make another thread to wait/pause by calling wait() method.

Locking mechanism (synchronization) is the safest way to make the other threads to wait till the execution of the thread which acquired the lock to complete.

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