// // utility class to display info about current thread, or all // threads in current thread group. // see main program for example of use. to use methods // elsewhere, reference as, e.g., ShowThreads.show("message"). // class ShowThreads { // writes to standard output info about current thread, plus // a user-supplied identifying message. static void show(String msg) { System.out.println(msg + ": current thread = " + Thread.currentThread()) ; } // writes to standard output info about all active threads, plus // a user-supplied identifying message. static void showAll(String msg) { System.out.println(msg + ": active threads = ") ; Thread.currentThread().getThreadGroup().list() ; } // first delays, then invokes showAll above (useful, e.g., // when starting an AWT program, to give the runtime // system time to start the AWT threads). static void showAll(String msg, int seconds) { try { Thread.currentThread().sleep( (long) (1000 * seconds)) ; } catch (InterruptedException e) { } showAll(msg) ; } // // no command-line arguments. // public static void main(String[] args) { show("in main") ; showAll("in main") ; showAll("in main after 10 secs", 10) ; Thread t1 = new Thread() ; showAll("in main after creating new thread") ; } }