Tuesday, 29 November 2016

Program for pausing thread.

This program demonstrates you how to pause the execution of thread. The sleep(long millis) method of Thread class causes the currently executing thread to sleep for the specified number of milliseconds. This method throws an InterruptedException exception. The output of this program is first it print "Hello" after 1 second "from" will print and then "Java" will print after 1 second.


PROGRAM
public class PausingThread {

 public static void main(String[] args) {
  
  try{
   System.out.println("Hello");
   Thread.sleep(1000);
   System.out.println("from");
   Thread.sleep(1000);
   System.out.println("Java.");
   Thread.sleep(1000);
  }
  catch (InterruptedException e){ }
 }
}
OUTPUT
C:\>javac PausingThread.java
C:\>java PausingThread
Hello
from
Java.

No comments:

Post a Comment