14 public void run(String arg) {
17 CharArrayWriter caw =
new CharArrayWriter();
18 PrintWriter pw =
new PrintWriter(caw);
21 new TextWindow(
"Threads", caw.toString(), 300, 300);
28 private static void print_thread_info(PrintWriter out, Thread t,
30 if (t == null)
return;
31 out.print(indent +
"Thread: " + t.getName() +
32 " Priority: " + t.getPriority() +
33 (t.isDaemon()?
" Daemon":
"") +
34 (t.isAlive()?
"":
" Not Alive") +
"\n");
38 private static void list_group(PrintWriter out, ThreadGroup g,
40 if (g == null)
return;
41 int num_threads = g.activeCount();
42 int num_groups = g.activeGroupCount();
43 Thread[] threads =
new Thread[num_threads];
44 ThreadGroup[] groups =
new ThreadGroup[num_groups];
46 g.enumerate(threads,
false);
47 g.enumerate(groups,
false);
49 out.println(indent +
"Thread Group: " + g.getName() +
50 " Max Priority: " + g.getMaxPriority() +
51 (g.isDaemon()?
" Daemon":
"") +
"\n");
53 for(
int i = 0; i < num_threads; i++)
54 print_thread_info(out, threads[i], indent +
" ");
55 for(
int i = 0; i < num_groups; i++)
56 list_group(out, groups[i], indent +
" ");
60 public static void listAllThreads(PrintWriter out) {
61 ThreadGroup current_thread_group;
62 ThreadGroup root_thread_group;
66 current_thread_group = Thread.currentThread().getThreadGroup();
69 root_thread_group = current_thread_group;
70 parent = root_thread_group.getParent();
71 while(parent != null) {
72 root_thread_group = parent;
73 parent = parent.getParent();
77 list_group(out, root_thread_group,
"");