简体   繁体   English

如何知道JVM目前是否正在进行GC?

[英]How to know if the JVM is currently doing GC ?

I have a use case, where I need to stop requests being sent to a java restful service, if the JVM of the service is currently doing a GC. 我有一个用例,如果服务的JVM当前正在执行GC,我需要停止将请求发送到java restful服务。 How/which API can hep me to find this ? 怎么/哪个API可以帮我找到这个?

There are different ways to monitor GC, but the only difference is how the GC operation information is shown. 有不同的方法来监控GC,但唯一的区别是GC操作信息的显示方式。 GC is done by JVM, and since the GC monitoring tools disclose the GC information provided by JVM, you will get the same results no matter how you monitor GC. GC由JVM完成,由于GC监控工具公开了JVM提供的GC信息,无论您如何监控GC,都会得到相同的结果。

The GC monitoring methods can be separated into CUI and GUI depending on the access interface. 根据访问接口,GC监视方法可以分为CUIGUI The typical CUI GC monitoring method involves using a separate CUI application called "jstat", or selecting a JVM option called "verbosegc" when running JVM. 典型的CUI GC监视方法涉及使用名为“jstat”的单独CUI应用程序,或在运行JVM时选择名为“verbosegc”的JVM选项。

jstat is a monitoring tool in HotSpot JVM. jstat是HotSpot JVM中的监视工具。 Other monitoring tools for HotSpot JVM are jps and jstatd. HotSpot JVM的其他监视工具是jps和jstatd。 Sometimes, you need all three tools to monitor a Java application. 有时,您需要所有三个工具来监视Java应用程序。

- verbosegc is one of the JVM options specified when running a Java application. - verbosegc是运行Java应用程序时指定的JVM选项之一。 While jstat can monitor any JVM application that has not specified any options, -verbosegc needs to be specified in the beginning, so it could be seen as an unnecessary option (since jstat can be used instead). 虽然jstat可以监视任何未指定任何选项的JVM应用程序,但是需要在开头指定-verbosegc,因此可以将其视为不必要的选项(因为可以使用jstat)。

You can probably do this by using visualVM and it's API. 您可以通过使用visualVM及其API来实现此目的。 The visual vm is the visualization of the GC process. visual vm是GC过程的可视化。 But it has it's own API as well. 但它也拥有自己的API。 Visual VM Visual VM

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

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