public static void addWatchDogToAllPools(final long threshold,
final NotificationListener listener) {
final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
final NotificationEmitter ne = (NotificationEmitter) memBean;
ne.addNotificationListener(listener, null, null);
final List<MemoryPoolMXBean> memPools = ManagementFactory
.getMemoryPoolMXBeans();
for (final MemoryPoolMXBean mp : memPools) {
if (mp.isUsageThresholdSupported()) {
final MemoryUsage mu = mp.getUsage();
final long max = mu.getMax();
final long alert = (max * threshold) / 100;
// LOG.info("Setting a threshold shutdown on pool: " + mp.getName()
// + " for: " + alert);
mp.setUsageThreshold(alert);
}
}
}
MemoryWatchdog.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:pitest
作者:
评论列表
文章目录