use of java.lang.management.MemoryNotificationInfo in project btrace by btraceio.
the class BTraceRuntime method initMemoryListener.
private void initMemoryListener() {
initThreadPool();
memoryListener = new NotificationListener() {
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void handleNotification(Notification notif, Object handback) {
boolean entered = BTraceRuntime.enter(BTraceRuntime.this);
try {
String notifType = notif.getType();
if (notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
CompositeData cd = (CompositeData) notif.getUserData();
final MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
String name = info.getPoolName();
final LowMemoryHandler handler = lowMemoryHandlerMap.get(name);
if (handler != null) {
threadPool.submit(new Runnable() {
@Override
public void run() {
boolean entered = BTraceRuntime.enter(BTraceRuntime.this);
try {
if (handler.trackUsage) {
handler.invoke(clazz, null, info.getUsage());
} else {
handler.invoke(clazz, null, (Object[]) null);
}
} catch (Throwable th) {
} finally {
if (entered) {
BTraceRuntime.leave();
}
}
}
});
}
}
} finally {
if (entered) {
BTraceRuntime.leave();
}
}
}
};
}
Aggregations