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.

Comments

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.