Thread name in Java

In Java, every thread has a name, the name can be either the default name provided by JVM or the customized name given by the programmer.

public class ThreadName extends Thread {


}
   class ThreadNameDemo {
       public static void main(String[] args) {
           System.out.println(Thread.currentThread().getName());
           ThreadName object = new ThreadName();
           System.out.println(object.getName());
           Thread.currentThread().setName("TheCodeData main method");
           object.setName("TheCodeData Thread name demo");
           System.out.println(Thread.currentThread().getName());
           System.out.println(object.getName());
       }
   }
Thread name in Java

Similar Java Tutorials

Leave a Comment