View Javadoc

1   package org.catacomb.dataview;
2   
3   import org.catacomb.graph.gui.DataDisplay;
4   import org.catacomb.report.E;
5   
6   
7   public class Plotter {
8   
9   
10      // not much here -= just testing vm exit
11      public static void main(String[] argv) {
12  
13          DataDisplay.setBatch();
14  
15          // DataDisplay dd = new DataDisplay(100, 100);
16  
17  //      WorldCanvas wc = new WorldCanvas(100, 100);
18  
19          showThreads();
20  
21      }
22  
23  
24  
25  
26      public static void showThreads() {
27  
28          // Find the root thread group
29          ThreadGroup root = Thread.currentThread().getThreadGroup();
30          while (root.getParent() != null) {
31              root = root.getParent();
32          }
33  
34          // Visit each thread group
35          visit(root, 0);
36  
37      }
38  
39      // This method recursively visits all thread groups under `group'.
40      public static void visit(ThreadGroup group, int level) {
41          // Get threads in `group'
42          int numThreads = group.activeCount();
43          Thread[] threads = new Thread[numThreads*2];
44          numThreads = group.enumerate(threads, false);
45  
46          // Enumerate each thread in `group'
47          for (int i=0; i<numThreads; i++) {
48              // Get thread
49              Thread thread = threads[i];
50              E.info("Thread: " + thread.isDaemon() + " " + thread);
51          }
52  
53          // Get thread subgroups of `group'
54          int numGroups = group.activeGroupCount();
55          ThreadGroup[] groups = new ThreadGroup[numGroups*2];
56          numGroups = group.enumerate(groups, false);
57  
58          // Recursively visit each subgroup
59          for (int i=0; i<numGroups; i++) {
60              visit(groups[i], level+1);
61          }
62      }
63  
64  }