how to find number of threads and count of objects in a running Java application?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, March 22, 2002 04:58 AM

Is there any Java API to find the number of threads in JVM? Also is there any way to interact with the JVM and find out how many objects are currently available and individual count of objects type wise? Any clue is of great help, and also point me if there is any good links available on this topic.

Re: how to find number of threads and count of objects in a running Java application?

Posted By:   Simon_Ablett  
Posted On:   Tuesday, March 26, 2002 03:43 AM

You can enumerate around all the threads in a given ThreadGroup using the static 'Thread.enumerate()' method and the number of threads in a group is given by the static 'Thread.activeCount()' method. This might give you what you want if all threads are in the same group (or one of its children). I'm not sure if it will report any additional threads used internally by the JVM.

The following


import java.io.*;

public class TT
{
public static void main( String [] args )
{
System.out.println("Number of threads ("+Thread.activeCount()+")");
}
}

returns '1' for me when running under native threads on Solaris 2.6.

Regards.

Re: how to find number of threads and count of objects in a running Java application?

Posted By:   Christopher_Schultz  
Posted On:   Friday, March 22, 2002 11:44 AM

From within Java, you're generally out of luck.



If you look into the debugging and profiling API, you'll see that there are C hooks for observing a running VM. You should look into this.



-chris
About | Sitemap | Contact