com.sun.management.GarbageCollectionNotificationInfo Java Examples

The following examples show how to use com.sun.management.GarbageCollectionNotificationInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #2
Source File: GarbageCollectorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #3
Source File: GarbageCollectionNotificationContentTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #4
Source File: GarbageCollectionNotificationTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #5
Source File: GarbageCollectionNotificationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #6
Source File: GarbageCollectorImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #7
Source File: GcLogger.java    From spectator with Apache License 2.0 6 votes vote down vote up
private void processGcEvent(GarbageCollectionNotificationInfo info) {
  GcEvent event = new GcEvent(info, jvmStartTime + info.getGcInfo().getStartTime());
  gcLogs.get(info.getGcName()).add(event);
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(event.toString());
  }

  // Update pause timer for the action and cause...
  Id eventId = (isConcurrentPhase(info) ? CONCURRENT_PHASE_TIME : PAUSE_TIME)
    .withTag("action", info.getGcAction())
    .withTag("cause", info.getGcCause());
  Timer timer = Spectator.globalRegistry().timer(eventId);
  timer.record(info.getGcInfo().getDuration(), TimeUnit.MILLISECONDS);

  // Update promotion and allocation counters
  updateMetrics(info.getGcName(), info.getGcInfo());

  // Notify an event listener if registered
  if (eventListener != null) {
    try {
      eventListener.onComplete(event);
    } catch (Exception e) {
      LOGGER.warn("exception thrown by event listener", e);
    }
  }
}
 
Example #8
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #9
Source File: GarbageCollectorImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #10
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #11
Source File: GarbageCollectorImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #12
Source File: GarbageCollectorImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #13
Source File: GarbageCollectionNotificationContentTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #14
Source File: GCNotificationEventEmitter.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a JMX {@link Notification} emitted by one of the GC beans that we're listening to. This
 * function is called on a special runtime thread that is not visible to debuggers, so if you're
 * trying to break in this method and it's not working, that's why.
 *
 * <p>Since this is called on a special thread, it's important that it 1) not block and 2)
 * terminate as quickly as possible.
 *
 * @param notification The notification that we've just received from JMX
 * @param handback An instance of the {@link GarbageCollectorMXBean} that triggered the event,
 *     which we passed explicitly as the third parameter of {@link
 *     NotificationEmitter#addNotificationListener(NotificationListener, NotificationFilter,
 *     Object)} in the class constructor.
 */
@Override
public void handleNotification(Notification notification, Object handback) {
  // It's unlikely that the GC bean emits anything other than GC notifications, but the docs say
  // to check, so we do.
  if (notification
      .getType()
      .equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
    GarbageCollectionNotificationInfo notificationInfo =
        GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
    GcInfo info = notificationInfo.getGcInfo();
    if (isMinorGCBean((GarbageCollectorMXBean) handback)) {
      eventBus.post(new GCMinorCollectionEvent(info));
    } else {
      eventBus.post(new GCMajorCollectionEvent(info));
    }
  }
}
 
Example #15
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #16
Source File: GarbageCollectorImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #17
Source File: OldGarbageCollectorListener.java    From kanela with Apache License 2.0 6 votes vote down vote up
private void processGCEvent(GarbageCollectionNotificationInfo info) {
    if(tools.isEndOfMayorGC(info.getGcAction())) {
        val after = info.getGcInfo().getMemoryUsageAfterGc();

        val percentageFreeMemory = oldGenPool.map((pool) -> {
            val totalMemoryAfterGc = after.get(pool.getName()).getMax();
            val usedMemoryAfterGc = after.get(pool.getName()).getUsed();
            val freeMemoryGc = ((double) totalMemoryAfterGc - usedMemoryAfterGc) / totalMemoryAfterGc;
            return 100.0 * freeMemoryGc;
        });

        percentageFreeMemory.forEach((freeMemory) -> {
            val event = GcEvent.from(info, (double) freeMemory, jvmStartTime + info.getGcInfo().getStartTime());
            if(config.isShouldLogAfterGc()) {
                Logger.warn(() -> format("{0}", event));
            }
            broker.publish(event);
        });
    }
}
 
Example #18
Source File: GarbageCollectionNotificationTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #19
Source File: GarbageCollectorImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #20
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #21
Source File: GarbageCollectionNotificationTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #22
Source File: GarbageCollectionNotificationTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #23
Source File: PostGCMemoryUseRecorderTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static Notification createMockNotification(
    String type, String action, String cause, Map<String, Long> memUsed) {
  ImmutableMap.Builder<String, MemoryUsage> memUsageMap = ImmutableMap.builder();
  for (Map.Entry<String, Long> e : memUsed.entrySet()) {
    memUsageMap.put(e.getKey(), createMockMemoryUsage(e.getValue()));
  }
  GcInfo gcInfo = mock(GcInfo.class);
  when(gcInfo.getMemoryUsageAfterGc()).thenReturn(memUsageMap.build());

  GarbageCollectionNotificationInfo notInfo =
      new GarbageCollectionNotificationInfo("DummyGCName", action, cause, gcInfo);

  Notification n = mock(Notification.class);
  when(n.getType()).thenReturn(type);
  when(n.getUserData()).thenReturn(notInfo.toCompositeData(null));
  return n;
}
 
Example #24
Source File: GarbageCollectionNotificationTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #25
Source File: GarbageCollectionNotificationTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #26
Source File: GarbageCollectionNotificationTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #27
Source File: JVMUtils.java    From babar with Apache License 2.0 6 votes vote down vote up
/**
 * Register to all notifications from the GC MXBeans.
 * @param listener          A java NotificationListener
 */
public static void registerGCListener(GCListener listener) {

    // takes the GC listener and makes javax NotificationListener that filters GC notifications
    NotificationListener notificationListener = new NotificationListener() {
        @Override
        public void handleNotification(Notification notification, Object handback) {
            if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) return;

            // get the GC info object
            GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData)notification.getUserData());
            String gcAction = info.getGcAction();
            if (MINOR_GC_ACTION.equals(gcAction)) {
                listener.onMinorGc(info.getGcInfo().getDuration());
            }
            else if (MAJOR_GC_ACTION.equals(gcAction)) {
                listener.onMajorGc(info.getGcInfo().getDuration());
            }
        }
    };

    // register to the GC beans
    for (GarbageCollectorMXBean bean: ManagementFactory.getGarbageCollectorMXBeans()) {
        ((NotificationEmitter)bean).addNotificationListener(notificationListener, null, null);
    }
}
 
Example #28
Source File: GarbageCollectionNotificationContentTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(listenerInvoked.get(source) == null) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),gcNotif);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #29
Source File: GarbageCollectionNotificationTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        GarbageCollectionNotificationInfo gcNotif =
            GarbageCollectionNotificationInfo.from((CompositeData) notif.getUserData());
        String source = ((ObjectName)notif.getSource()).getCanonicalName();
        synchronized(synchronizer) {
            if(!listenerInvoked.get(source)) {
                    listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
                    count++;
                    if(count >= number) {
                        synchronizer.notify();
                    }
            }
        }
    }
}
 
Example #30
Source File: GarbageCollectionMonitor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public void handleNotification(Notification notification, Object handback) {
  if (GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) {
    GarbageCollectionNotificationInfo notificationInfo = from((CompositeData) notification.getUserData());
    GcInfo info = notificationInfo.getGcInfo();

    if (info != null && !"No GC".equals(notificationInfo.getGcCause())) {
      registerPause(info.getDuration());
    }
  }
}