/** * Start collecting data about GC events. * * @param listener * If not null, the listener will be called with the event objects after metrics and the * log buffer is updated. */ public synchronized void start(GcEventListener listener) { // TODO: this class has a bad mix of static fields used from an instance of the class. For now // this has been changed not to throw to make the dependency injection use-cases work. A // more general refactor of the GcLogger class is needed. if (notifListener != null) { LOGGER.warn("logger already started"); return; } eventListener = listener; notifListener = new GcNotificationListener(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { if (mbean instanceof NotificationEmitter) { final NotificationEmitter emitter = (NotificationEmitter) mbean; emitter.addNotificationListener(notifListener, null, null); } } }
/** * Start collecting data about GC events. * * @param listener * If not null, the listener will be called with the event objects after metrics and the * log buffer is updated. */ public synchronized void start(GcEventListener listener) { // TODO: this class has a bad mix of static fields used from an instance of the class. For now // this has been changed not to throw to make the dependency injection use-cases work. A // more general refactor of the GcLogger class is needed. if (notifListener != null) { LOGGER.warn("logger already started"); return; } eventListener = listener; notifListener = new GcNotificationListener(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { if (mbean instanceof NotificationEmitter) { final NotificationEmitter emitter = (NotificationEmitter) mbean; emitter.addNotificationListener(notifListener, null, null); } } }