Demo Thread Program in Java

 class Demo   
 {  
   public static void main (String args[] ) {  
    Thread t = Thread.currentThread();  
    System.out.println("Current thread: " + t);  
    t.setName("Demo Thread");  
    System.out.println("Renamed Thread: " + t);  
   }  
 }  
 /** output:  
 Thread[main, 5,main]  
 Renamed Thread:[Demo Thread,5,main]  
 Information within the square brackets tells us something about the thread.   
 The first appearance of the word main is the name of the thread.   
 The number 5 is the thread’s priority, which is normal priority.   
 The priority ranges from 1 to 10, where 1 is the lowest priority and 10 is the highest.   
 The last occurrence of the word main is the name of the group of threads with which the   
 thread belongs. A thread group is a data structure used to control the state of a collection   
 of threads. You don’t need to be concerned about a thread group because the Java run-time   
 environment handles this.  
 */  

Post a Comment

0 Comments