How can I find out how many threads are running in the JVM?

I believe you can call getParent() recursively on the current ThreadGroup (System.currentThread().getThreadGroup()) until you find the toplevel ThreadGroup. Then call enumerate to get an array with all threads. This seems pretty wasteful, though, and I'm sure there is a better way to do it.