Thread Class Methods
The Thread class possesses many useful static and instance methods. The important methods that are available in the Thread class are briefly described in the following table:
Getting Thread Name
You can obtain the name assigned to a thread by calling the getName( ) method for the Thread object. The name of the thread is returned as a default Thread name (Thread-0,Thread-1, Thread-2,…………).
Program
Program Source
class NewThread extends Thread { void changeName(String str) { setName(str); } public void run() { System.out.println("Exiting : "+getName()); } } public class Javaapp { public static void main(String[] args) { NewThread th1 = new NewThread(); th1.start(); NewThread th2 = new NewThread(); th2.start(); NewThread th3 = new NewThread(); th3.changeName("Child-2"); th3.start(); } }