Swing Components in Default ProcessingWindow

If you are interested in finding out what threads are being executed then this might be helpful, as it allows you to display information about all running threads in your application.

This sketch has 2 tabs, the second one is a Java tab NOT a pde tab.

Try running the sketch and then closing the window, with Task Manager open.

Main Sketch Tab

void settings() {
  size(300, 300);
}

void setup() {
  println("\n###### setup() ########");
  ThreadInfo.printAllThreadInfo();
}

void draw() {
  background(255);
}

void exit() {
  println("\n###### exit() ########");
  ThreadInfo.printAllThreadInfo();
}

Java tab named
ThreadInfo.java

/*
 * Created on 25-Aug-2004
 * Modified 26th November 2015
 *
 * @author Peter Lager
 *
 */
public class ThreadInfo {

  public static void printAllThreadInfo() {
    ThreadGroup root;
    // find the root of all running threads
    //root = parent = Thread.currentThread().getThreadGroup();
    root = Thread.currentThread().getThreadGroup();
    while (root.getParent() != null) 
      root = root.getParent();
    printThreadGroupInfo("", root);
    System.out.println("------------------------------------------------------\n");
  }

  private static void printThreadGroupInfo(String indent, ThreadGroup group) {
    final int SAFETY = 5;
    if (group == null) return;

    System.out.println(indent + "THREAD GROUP: " + group.getName() +
      ": Max Priority: " + group.getMaxPriority() + 
      (group.isDaemon() ? "[Daemon]" : ""));
    // print information about component threads
    int numThreads = group.activeCount();
    Thread threads[] = new Thread[numThreads + SAFETY];
    numThreads = group.enumerate(threads, false);
    for (int i = 0; i < numThreads; i++)
      printThreadInfo(indent + "   ", threads[i]);
    // print infomation about component thread groups
    int numGroups = group.activeGroupCount();
    ThreadGroup groups[] = new ThreadGroup[numGroups + SAFETY];
    numGroups = group.enumerate(groups, false);
    for (int i = 0; i < numGroups; i++)
      printThreadGroupInfo(indent + "   ", groups[i]);
  }

  private static void printThreadInfo(String indent, Thread thread) {
    if (thread == null) return;

    System.out.println(indent + "THREAD: " + thread.getName() +
      ": Priority: " + thread.getPriority() +
      (thread.isDaemon() ? " [Daemon]" : "") +
      (thread.isAlive() ? " [Alive]" : " [NotAlive]")+
      ((Thread.currentThread() == thread) ? " <== Current" : ""));
  }
}
4 Likes