// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class TreadTracking implements Runnable {
    public static void main(String[] args) throws Exception {
        System.out.println("before:");
        Thread[] t = new Thread[Thread.activeCount()];
        Thread.enumerate(t);
        for(int i = 0; i < t.length; i++) {
            System.out.println("  " + t[i].getName());
        }
        t = null;
        new Thread(new TreadTracking()).start();
        System.out.println("during:");
        t = new Thread[Thread.activeCount()];
        Thread.enumerate(t);
        for(int i = 0; i < t.length; i++) {
            System.out.println("  " + t[i].getName());
        }
        t = null;
        Thread.sleep(2000);
        System.out.println("after:");
        t = new Thread[Thread.activeCount()];
        Thread.enumerate(t);
        for(int i = 0; i < t.length; i++) {
            System.out.println("  " + t[i].getName());
        }
    }
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
}
