如何从JVM中检测一个很长的gc? [英] How to detect a long gc from within a JVM?

查看:83
本文介绍了如何从JVM中检测一个很长的gc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测超过某些配置应用超时的GC(编辑或任何暂停),以便我可以记录警告(或动态延长超时)?

How can I detect a GC (Edit or any stall) which exceeds some configured app timeout so that I can log a warning (or dynamically extend the timeout)?

编辑我不会要求替代方法或解决方法。我在写图书馆,我无法控制环境或设置。虽然我会清楚地记录图书馆的用户必须设置适当的超时时间,但我仍然期望人们忽略其他人在几年后改变jvm堆设置并忘记增加超时时间。如果我可以在库中记录可能的暂停超过配置的超时,则支持将会更简单。它不一定是完美的检测足够好,可以减少图书馆用户浪费时间而不是设置明智的超时。

Edit I am not asking for alternatives or workarounds like monitoring. I am writing a library and I cannot control the environment or settings. Whilst I will clearly document that users of the library must set an appropriate timeout I still expect people to overlook that else change jvm heap settings years later and forget to increase the timeouts. Support will be simpler if I can warn in the library logging of a possible pause greater than the configured timeouts. It doesn't have to be perfect detection "good enough" would reduce time wasted on library users not setting a sensible timeout.

编辑和要清楚的是,即使存在大的GC,库仍能正常工作,但有充足的理由有足够的时间来检测崩溃,以便库尝试连接到备用对等体。

Edit and to be clear the library works fine even if there is a big GC yet there is a good reason to have well chosen timeout which is to detect a crash such that the library tries to connect to an alternate peer.

推荐答案

您可以使用管理bean 通知并订阅 GARBAGE_COLLECTION_NOTIFICATION 这些事件又提供了 GcInfo 包含所需统计信息的对象。

You can use management bean notifications and subscribe to GARBAGE_COLLECTION_NOTIFICATION events which in turn provide GcInfo objects with the stats you want.

javax.management package javadocs 具有高层次的概述如何使用这些服务。

The javax.management package javadocs have a high level overview how to use those services.

这篇关于如何从JVM中检测一个很长的gc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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