General Thread Information
To print thread or thread group information, use the following methods:
- String toString()
Returns a string that describes the Thread object. Originally a method of the Object class, it is overridden by the Thread class to provide the name of the thread, the priority of the thread, and the name of the thread group to which the thread belongs.
- String toString()
Returns a string that describes the ThreadGroup object. Originally a method of the Object class, it is overridden by the ThreadGroup class to provide the name of the thread group and the maximum priority of the group.
The toString() method is overridden by the
thread classes to allow a sensible conversion of the object into a
string. Hence, the following code:
Thread t = new TimerThread(this, 500);
System.out.println(t);yields the following output:
Thread[TimerThread-500,6,group applet-TimerApplet]
- void list()
Prints the current layout of the thread group hierarchy, starting with the thread group on which the method is invoked. This is a method of the ThreadGroup class and simply prints the information to
System.out. This method operates recursively on the thread group.
The information that is printed by the list()
method is the information returned by the
toString() methods. A sample
list() of an applet may be as follows:
java.lang.ThreadGroup[name=system,maxpri=10] Thread[clock handler,11,system] Thread[Idle thread,0,system] Thread[Async Garbage Collector,1,system] Thread[Finalizer thread,1,system] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access