Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the number of threads in a Java process

How can I see the number of threads in a Java process?

like image 562
ndemir Avatar asked Dec 17 '09 14:12

ndemir


People also ask

How do you count threads in Java?

The java. lang. Thread. activeCount() method returns the number of active threads in the current thread's thread group.


2 Answers

java.lang.Thread.activeCount() 

It will return the number of active threads in the current thread's thread group.

docs: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#activeCount()

like image 191
miku Avatar answered Oct 09 '22 10:10

miku


ManagementFactory.getThreadMXBean().getThreadCount() doesn't limit itself to thread groups as Thread.activeCount() does.

like image 26
gustafc Avatar answered Oct 09 '22 10:10

gustafc