获取所有JVM使用的所有Java类的列表? [英] Obtaining a list of all Java classes used from all JVM's?

查看:300
本文介绍了获取所有JVM使用的所有Java类的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个列表,列出某个时刻在多个线程/ JVM中加载的所有类。

I want to have a list of all the classes that are loaded within multiple threads/JVM's at a certain moment in time.

我知道,当您使用 -verbose 参数运行Java时,可以将其作为文件写入文件像这样: java -verbose:class com.package.Foo> classes-used.txt

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

但是,我的主程序中有使用Shell脚本启动新jar的线程。我想避免在每个shell脚本中都写 -verbose 参数,我想知道在Linux上是否还有其他方法可以做到这一点?

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?

推荐答案

您可以使用JDK随附的jcmd命令。启动时不需要任何特殊参数传递给JVM。

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 

将列出当前正在运行的所有JVM及其pid(进程ID)。

Will list all of the JVMs that are currently running, along with their pid (process id).

jcmd <pid> GC.class_histogram

将列出该JVM中当前加载的每个类,并列出多少个实例。

will then list every class that is currently loaded in that JVM, along with a count of how many instances.

这篇关于获取所有JVM使用的所有Java类的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆