Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name of main thread

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?

like image 946
Ameet Avatar asked Sep 26 '12 11:09

Ameet


1 Answers

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.

like image 180
Peter Lawrey Avatar answered Sep 26 '22 22:09

Peter Lawrey