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.
Thread.sleep[] Method Example
In this example, we have created and started two threads thread1 and thread2. Note that we have used both overloaded versions of sleep[] methods in this example.
Thread.sleep[1000]; Thread.sleep[1000, 500];
/** * thread sleep method examples * @author Ramesh fadatare * */ public class ThreadSleepExample { public static void main[final String[] args] { System.out.println["Thread main started"]; final Thread thread1 = new Thread[new WorkerThread[]]; thread1.setName["WorkerThread 1"]; final Thread thread2 = new Thread[new WorkerThread[]]; thread1.setName["WorkerThread 2"]; thread1.start[]; thread2.start[]; System.out.println["Thread main ended"]; } } class WorkerThread implements Runnable { @Override public void run[] { for [int i = 0; i