Pausing Execution

suggest change

Thread.sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system. There are two overloaded sleep methods in the Thread class. One specifies the sleep time in milliseconds:

public static void sleep(long millis) throws InterruptedException

One specifies milliseconds plus a nanosecond adjustment. It also throws InterruptedException:

public static void sleep(long millis, int nanos) throws InterruptedException

Pausing Execution for 1 second

Thread.sleep(1000);

It is important to note that this is a hint to the operating system’s kernel’s scheduler. This may not necessarily be precise, and some implementations do not even consider the nanosecond parameter (possibly rounding to the nearest millisecond).

It is recommended to enclose a call to Thread.sleep in a try/catch for InterruptedException.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents