Is it possible to register if a class is used in the JVM?

I have Tomcat running applications. I cannot restart Tomcat, but I would like to monitor the use of class files.

I would like to register if the specified class is used. Is it possible? How could I do this?

Using a class. If an object for this class is created or methods are called, etc.

Clarification: I cannot restart the application. Each solution with recompilation of working code is unacceptable. This makes the problem harder.

Remote debugging / JMX is not yet enabled. It will be a similar effort, for example, recompiling the application to activate it.

Platform - RHEL, 64 bit.

+5
source share
7 answers

, ; , ..

, . , ... - , .

Webapp , , , classloader, . , , EVER, EVER . .

, , , , .

, , , .

+1

, . , . fav - System.out.println:)

+1

, (, ).

, " ", , , , JVM? , ; .

0

, , .

, , .

ClassLoader#findLoadedClass()

null, , , , . , , , , .

0

Solaris OS X, DTrace-.

, JVM ( , ), .

0

class X {
 static {
  System.out.println("class X has been loaded");
 }
 ...
}

.

If you cannot edit the code and you have JRE 6, you can try the jmap tool

jmap -histo <pid>

it will display a histogram of your heap, including all loaded classes.

Using jps, you can find out pid

-1
source

With the JRockit JVM, you can run your application with -Xverbose: class = info to get information about loading classes.

-1
source

All Articles