Thread.sleep(long)
Let's look at the first type of unconditional synchronization, Thread.sleep.
The signature of the sleep(long) method is public static native void sleep(long) throws InterruptedException. There is an overloaded version of the sleep method, public static void sleep(long,int). Usually, the one with a single argument is used.
The sleep(long) method is a method in the Thread class that makes a particular thread wait for the specified number of milliseconds. When we enter Thread.sleep(5000); , we ask the main thread to wait for 5 seconds. Since the main thread stops, execution is halted for 5 seconds, after which the next statement is executed. If you put Thread.sleep() in many places in your code, you pause the main thread, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access