While working on the threads, sometimes we need to pause the execution of any thread – in that case, we need the concept of pausing the thread execution.
To pause the execution of a thread, we use "sleep()" method of Thread class.
Syntax:
Thread.currentThread().sleep(milliseconds);
Example:
Thread.currentThread().sleep(1000); //will pause the thread for 1 second
Thread.currentThread().sleep(10000); //will pause the thread for 10 seconds
Java code to pause the execution of a thread
Output