views:

95

answers:

3

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.

+8  A: 

From the javadoc of Thread:

public String toString()

Returns a string representation of this thread, including the thread's name, priority, and thread group.

Simon Groenewolt
+2  A: 

In the result:

Thread[main,5,main]

  • main is the thread's name
  • 5 is the priority and
  • main is the thread group.

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.

codaddict
A: 

Thanks Simon and bzabhi, should have gone to javadoc first!

torde