问题
I want to have a list of all the classes that are loaded within multiple threads/JVM's at a certain moment in time.
I know that when you run java with the -verbose parameter, you can write it to a file as something like this: java -verbose:class com.package.Foo > classes-used.txt
However, I have threads in my main program that use a shell script to start a new jar. I would like to avoid to have to write the -verbose parameter in every shell script and I'm wondering if there is any other way to do this on Linux?
回答1:
You could use the jcmd command that comes with the JDK. It does not require any special arguments to be past to the JVM upon start.
jcmd
Will list all of the JVMs that are currently running, along with their pid (process id).
jcmd <pid> GC.class_histogram
will then list every class that is currently loaded in that JVM, along with a count of how many instances.
来源:https://stackoverflow.com/questions/25081409/obtaining-a-list-of-all-java-classes-used-from-all-jvms