Simple Thread Example Program in Java

 //Write a program to find out the thread used by JVM to execute the statements.  
 class current   
 {  
      public static void main(String[] args)   
      {  
           System.out.println("Let's find current thread.. ");  
           Thread th=Thread.currentThread();  
           System.out.println("Current thread is: "+th);  
           System.out.println("Thread name is: "+th.getName());  
           System.out.println("Thread priority is: "+th.getPriority());  
           System.out.println("Thread is alive: "+th.isAlive());  
      }  
 }  
 /**  
 ouput: Thread [main, 5, main]  
 Thread name is: main  
 Thread priority is : 5  
 Thread is alive: true  
 Thread [main, 5, main] in this first main is the name of the thread,   
 5 is the priority of thread, third main indicates the thread group name   
 to which this thread belongs.  
 */  

Post a Comment

0 Comments