use of javax.management.NotificationEmitter in project Lucee by lucee.
the class MemoryControler method init.
public static synchronized void init(ConfigServer cs) {
if (init)
return;
// set level
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
types.put(pool.getName(), pool.getType());
// we should rather check for the pool name "Tenured Gen"?
if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
long maxMemory = pool.getUsage().getMax();
long warningThreshold = (long) (maxMemory * 0.9);
// long warningThreshold = maxMemory -(10*1024*1024);
pool.setUsageThreshold(warningThreshold);
}
}
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
NotificationEmitter emitter = (NotificationEmitter) mbean;
MemoryNotificationListener listener = new MemoryNotificationListener(types);
emitter.addNotificationListener(listener, null, cs);
init = true;
}
Aggregations