In this section of java tutorial we will learn about the Java Thread setName() method and its use. Then We will create an example and show its usage.
In this section of java tutorial we will learn about the Java Thread setName() method and its use. Then We will create an example and show its usage.
public class setname implements Runnable { @Override public void run() { System.out.println(Thread.currentThread()); } public static void main(String[] args) { Thread t1 = new Thread(new setname(), "Thread a"); t1.start(); Thread t2 = new Thread(new setname()); t2.setName("Thread b"); t2.start(); System.out.println(t1.getName()); } }
Output
Thread[Thread a,5,main] Thread a Thread[Thread b,5,main]