!7 import com.sun.management.GcInfo; p { NotificationListener listener = new NotificationListener { @Override public void handleNotification(Notification notification, O handback) { print("type: " + notification.getType()); if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { // extract garbage collection information from notification. GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()); //print("Cause: " + gcInfo.getGcCause(); pnlStruct(callAllMethodsInInterface(gcInfo, GarbageCollectionNotificationInfo.class); print(); } } }; // register our listener with all gc beans for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) ((NotificationEmitter) gcBean).addNotificationListener(listener, null, null); }