Can we able to change the name of main thread? and in main method
Thread t = Thread.currentThread();
System.out.println(t);
It prints :
Thread[main,5,main]
- here first thread name , second priority, third is thread group to which current thread belongs to.
Is it right?
What is thread group the third parameter?
From the Javadoc for Thread
public final void setName(String name)
Changes the name of this thread to be equal to the argument name.
and
public String toString()
Returns a string representation of this thread, including the thread's name, priority, and thread group.
Thread t = Thread.currentThread();
System.out.println(t);
t.setName("new thread name");
System.out.println(t);
prints
Thread[main,5,main]
Thread[new thread name,5,main]
To change the ThreadGroup's name you could use reflection but that's unlikely to be a good idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With