Java program to set and print thread name
// Java program to set and print thread name
public class Main {
public static void main(String[] args) {
String threadName;
Thread thrd1 = new Thread("Thread1");
Thread thrd2 = new Thread("Thread2");
thrd1.start();
thrd2.start();
threadName = thrd1.getName();
System.out.println("Thread Name: " + threadName);
threadName = thrd2.getName();
System.out.println("Thread Name: " + threadName);
}
}
Output
Thread Name: Thread1
Thread Name: Thread2