![]() |
VOOZH | about |
In Java, sometimes a thread needs to pause its execution for a specific period of time before continuing its work. This can be done using the Thread.sleep() method, which temporarily suspends the current thread.
Note: suspend() method is deprecated in the latest Java version.
Syntax:
public final void suspend()
Output
👁 Thread 2 is suspendedExplanation: Three threads (t1, t2, t3) are created and started, so they run concurrently and execute the run() method independently. Each thread prints its name and numbers 1–4 with a small delay, so the output appears interleaved and in random order due to multithreading.
Note: Thread t2 can be resumed by resume() method.