Q:

getting the number of threads in a Java VM using Java code

I am looking for a way to get the number of threads in a JAVA VM, using JAVA code. Any ideas?
Many thanks in advance

A:

Try this:
Thread.getAllStackTraces().size()

A:

I think, you can also get it using JMX using ThreadMXBean management interface. Here is a sample.

