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
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
No comments:
Post a comment