简体   繁体   English

获取所有JVM使用的所有Java类的列表?

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

I want to have a list of all the classes that are loaded within multiple threads/JVM's at a certain moment in time. 我想要一个在某个时刻在多个线程/ JVM中加载的所有类的列表。

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 我知道,当您使用-verbose参数运行Java时,可以将其像这样写入文件: 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. 但是,我的主程序中有使用Shell脚本启动新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? 我想避免必须在每个shell脚本中编写-verbose参数,并且我想知道在Linux上是否还有其他方法可以做到这一点?

You could use the jcmd command that comes with the JDK. 您可以使用JDK随附的jcmd命令。 It does not require any special arguments to be past to the JVM upon start. 启动时,不需要任何特殊参数即可将其传递给JVM。

jcmd 

Will list all of the JVMs that are currently running, along with their pid (process id). 将列出当前正在运行的所有JVM及其pid(进程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. 然后将列出该JVM中当前加载的每个类,以及计数多少个实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM