>

Friday, November 9, 2012

Thread Example

class ThreadExample{
  public static void main(String args[])
   {
        Thread th=new Thread();
      try{
          for(int i=0;i<10;i++)
    {
                System.out.println(" Value "+i);
     th.sleep(2000);
              }
          }
           catch(Exception e)
    {
     System.out.println(" "+e.getMessage());
    }
    }
         }

OUTPUT:

This program will print and pause for one second until next print.

 Value 0
 Value 1
 Value 2
 Value 3
 Value 4
 Value 5
 Value 6
 Value 7
 Value 8
 Value 9

No comments:

Post a Comment

Please post your comments. Your comments make us to write more programs for you.