/** * SystemThreadInfo enumerates all threads and thread groups. * * Copyright &copy; 1996-1998 Martin Minow. All Rights Reserved.<p> * * Permission to use, copy, modify, and redistribute this software and its * documentation for personal, non-commercial use is hereby granted provided that * this copyright notice and appropriate documentation appears in all copies. This * software may not be distributed for fee or as part of commercial, "shareware," * and/or not-for-profit endevors including, but not limited to, CD-ROM collections, * online databases, and subscription services without specific license.<p> * * @author <a href="mailto:minow@apple.com">Martin Minow</a> * @version 1.0 * Set tabs every 4 characters. */import java.util.*;import java.awt.*;public class SystemThreadInfo extends SystemInfo{	public SystemThreadInfo(			EtchedBorder		border		)	{		super(border);		try {			/*			 * Enumerate all threads and thread groups in the system.			 * See the sample in The Java Class Libraries, volume 1			 * in the Thread description.			 */			ThreadGroup	rootGroup		= Thread.currentThread().getThreadGroup();			while (rootGroup.getParent() != null) {				rootGroup				= rootGroup.getParent();			}			/*			 * Create a vector that contains all threads in all groups.			 */			Thread[]	threads			= new Thread[rootGroup.activeCount()];			int			threadCount		= rootGroup.enumerate(threads, true);			/*			 * Copy the thread information into a string vector.			 */			String[]	threadInfo		= new String[threadCount];			for (int i = 0; i < threadCount; i++) {				Thread	t				= threads[i];				StringBuffer	state = new StringBuffer(						(t.isAlive() ? "Alive" : "Dormant")					);				if (t.isInterrupted()) {					state.append(", Interrupted");				}				if (t.isDaemon()) {					state.append(", Daemon");				}				threadInfo[i]			=						t.getThreadGroup().getName()				+ ", "						+ t.getName()								+ ", "						+ "Priority: "		+ t.getPriority()		+ ", "						+ "Stack Frames: "	+ t.countStackFrames()	+ ", "						+ state.toString()						+ "\n"					;			}			threads						= null;	/* Dump the vector	*/			JavaInfo.quickSort(threadInfo, 0, threadCount - 1);			/*			 * Now that the threads are organized by group, add			 * them to the display. (We could, of course, scan			 * through the list again to cleanup the formatting.			 */			for (int i = 0; i < threadCount; i++) {				append(threadInfo[i]);			}			threadInfo					= null;			}		catch (Exception e) {			append("ThreadGroupInfo strange error: " + e + "\n");			e.printStackTrace();		}	}}