The easiest way to delay a java program is by using Thread. sleep() method. The sleep() method is present in the Thread class. It simply pauses the current thread to sleep for a specific time.
How do I put Java to sleep?
Use Thread. sleep(1000) ; 1000 is the number of milliseconds that the program will pause.
How does Java sleep work?
When a thread blocks, it is usually suspended and placed in one of the blocked thread states. So, when you call the sleep() method, Thread leaves the CPU and stops its execution for a period of time. During this time, it’s not consuming CPU time, so the CPU can be executing other tasks.