javatutelearn.com

Easy Learning


Home

Search Javatutelearn.com :



sleep() method of thread

  • sleep() pauses the execution of current thread for specified time in milliseconds.

Syntax

Example

 public class  sleepthread  extends Thread  {
	public void  run(){
			try  {
		 	Thread.sleep(5000);
			}
			catch  (Exception e){
			    System.out.println("Error..");
			}
			System.out.println(Thread.currentThread().getName()+ " is active now.");
	}
	public static void main (String args[]){
		sleepthread t1 = new sleepthread();
		 t1.start();	
	}
}

Output

Note:- Thread-0 sleeps for 5000 milliseconds. Then it displays output.
Thread-0 is active now





© Copyright 2016-2024 by javatutelearn.com. All Rights Reserved.