For example,
System.out.println( Thread.currentThread() );
gives
Thread[main,5,main]
What does [main,5,main] refer to? I am guessing perhaps one of them is the name, but I want to know what it all means precisely.
For example,
System.out.println( Thread.currentThread() );
gives
Thread[main,5,main]
What does [main,5,main] refer to? I am guessing perhaps one of them is the name, but I want to know what it all means precisely.
From the javadoc of Thread:
public String toString()
Returns a string representation of this thread, including the thread's name, priority, and thread group.
In the result:
Thread[main,5,main]
The function currentThread()
returns a reference to the currently executing thread object and when we try to print any object, the toString()
method of the corresponding class gets called, so in this case toString() method of the Thread class gets called and it returns a string representation of this thread, including the thread's name, priority, and thread group.