Program for Naming a Thread

This program demonstrates you how to change the thread name. The setName(String) method of Thread class is used to set the name of thread.


PROGRAM
public class NamingThread {

 public static void main(String[] args) {
  
  Thread thread = Thread.currentThread();
  System.out.println("Main thread's original name is : "+thread.getName());
  thread.setName("The Main Thread");
  System.out.println("Main thread's new name is : "+thread.getName());
 }

}
OUTPUT
C:\>javac NamingThread.java
C:\>java NamingThread
Main thread's original name is : main
Main thread's new name is : The Main Thread

Comments

Popular posts from this blog

Develop an Android application to display “Hello World!” on screen

Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Build a Simple Android App to Display Student Details