How to Temporarily Stop a Thread in Java?
The suspend() method of thread class puts the thread from running to waiting state. This method is employed if you would like to prevent the thread execution and begin it again when a particular event occurs. This method allows a thread to temporarily cease execution. The suspended thread is often resumed using the resume() method. If the present thread cannot modify the target thread then it’ll throw Security Exception.
Note: suspend() method is deprecated in the latest Java version.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public final void suspend()
Return: Does not return any value.
Exception: Throws SecurityException If the current thread cannot modify the thread.
Note: Thread t2 can be resumed by resume() method.