Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Pause thread in java (Java)

Source code below will print hi after pause for 5 seconds.

********************************************************
COMPLETE SOURCE CODE FOR : ThreadPause.java
********************************************************
public class ThreadPause extends Thread
{
public void run()
{
 //Pause thread for 5 seconds before print hi
 try
 {
  sleep(5000);
 }
 catch(Exception exception)
 {
  exception.printStackTrace();
 }

 //Print hi
 System.out.println("hi");
}

public static void main(String[]args)
{
 //Create a thread by create ThreadPause object
 ThreadPause a=new ThreadPause();

 //Start the thread
 a.start();
}
}


********************************************************
JUST COMPILE AND EXECUTE IT
********************************************************