List<GarbageCollectorMXBean> mxBeans = ManagementFactory
.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gcBean : mxBeans) {
NotificationEmitter emitter = (NotificationEmitter) gcBean;
NotificationListener listener = new NotificationListener() {
@Override
public void handleNotification(Notification notification,
Object handle) {
if (notification.getType().equals(GarbageCollectionNotificationInfo
.GARBAGE_COLLECTION_NOTIFICATION)) {
GarbageCollectionNotificationInfo info =
GarbageCollectionNotificationInfo.from(
(CompositeData) notification.getUserData());
if (LOG.isInfoEnabled()) {
LOG.info("gcmonitor: name = " + info.getGcName() +
", action = " + info.getGcAction() + ", cause = " +
info.getGcCause() + ", duration = " +
info.getGcInfo().getDuration() + "ms");
}
}
}
Java Garbage Collector (GC) Monitor
猜你喜欢
转载自blog.csdn.net/houzhizhen/article/details/106755716
今日推荐
周排行