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, which can slow down execution to a considerable extent. Therefore, it is not recommended that you use Thread.sleep(long) in your code, and that you instead use conditional synchronization.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.132.97