static void onGCNotification(final VF1 theListener) { NotificationListener listener = new NotificationListener { public void handleNotification(Notification notification, O handback) { // extract garbage collection information from notification. GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()); pcallF(theListener, gcInfo); } }; for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) ((NotificationEmitter) gcBean).addNotificationListener(listener, null, null); }