Advertisement
hcyuser

mainthread.java

May 3rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. public class Main_Thread
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         Thread t = Thread.currentThread();
  6.         System.out.println("Current thread: " + t);
  7.          
  8.         // change the name of the thread
  9.         t.setName("My Thread");
  10.         System.out.println("After name change: " + t);
  11.         try
  12.         {
  13.             for(int n = 5; n > 0; n--)
  14.             {
  15.                 System.out.println(n);  //print number with interval of 1 sec.
  16.                 Thread.sleep(1000);     //Thread is going to sleep for 1 sec.
  17.             }
  18.         }
  19.         catch (InterruptedException e)
  20.         {
  21.             System.out.println("Main thread interrupted");
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement