Obtaining a list of all Java classes used from all JVM's?

爷,独闯天下 提交于 2019-12-12 21:31:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!