当前位置: 首页>>代码示例>>Java>>正文


Java GarbageCollectionNotificationInfo类代码示例

本文整理汇总了Java中com.sun.management.GarbageCollectionNotificationInfo的典型用法代码示例。如果您正苦于以下问题:Java GarbageCollectionNotificationInfo类的具体用法?Java GarbageCollectionNotificationInfo怎么用?Java GarbageCollectionNotificationInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GarbageCollectionNotificationInfo类属于com.sun.management包,在下文中一共展示了GarbageCollectionNotificationInfo类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: installGCMonitoring

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
private static void installGCMonitoring() {
    List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gcbean : gcbeans) {
        NotificationEmitter emitter = (NotificationEmitter) gcbean;
        System.out.println(gcbean.getName());

        NotificationListener listener = (notification, handback) -> {
            if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

                long duration = info.getGcInfo().getDuration();
                String gctype = info.getGcAction();

                System.out.println(gctype + ": - "
                        + info.getGcInfo().getId() + ", "
                        + info.getGcName()
                        + " (from " + info.getGcCause() + ") " + duration + " milliseconds");

            }
        };

        emitter.addNotificationListener(listener, null, null);
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:25,代码来源:Main.java

示例2: createGCNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:GarbageCollectorImpl.java

示例3: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
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();
                    }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:GarbageCollectionNotificationContentTest.java

示例4: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
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();
                    }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:GarbageCollectionNotificationTest.java

示例5: createGCNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
protected 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:GarbageCollectorExtImpl.java

示例6: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
    if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
        System.out.println("0XDEADBEAF");
        GarbageCollectionNotificationInfo notifInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

        GcInfo gcInfo = notifInfo.getGcInfo();
        System.out.printf("Action: %s, %s, %s\n", notifInfo.getGcAction(), notifInfo.getGcCause(), notifInfo.getGcName());
        System.out.printf("Time: %d, %d, %d\n", gcInfo.getStartTime(), gcInfo.getEndTime(), gcInfo.getDuration());
        System.out.printf("Memory: %s, %s\n", gcInfo.getMemoryUsageBeforeGc().toString(), gcInfo.getMemoryUsageAfterGc().toString());



        Map<String, MemoryUsage> memBefore = notifInfo.getGcInfo().getMemoryUsageBeforeGc();
        Map<String, MemoryUsage> memAfter = notifInfo.getGcInfo().getMemoryUsageAfterGc();
        StringBuilder sb = new StringBuilder();
        sb.append("[").append(notifInfo.getGcAction()).append(" / ").append(notifInfo.getGcCause())
                .append(" / ").append(notifInfo.getGcName()).append(" / (");
        appendMemUsage(sb, memBefore);
        sb.append(") -> (");
        appendMemUsage(sb, memAfter);
        sb.append("), ").append(notifInfo.getGcInfo().getDuration()).append(" ms]");
        System.out.println(sb.toString());
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:26,代码来源:MemoryUtil.java

示例7: handleNotification

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
    try {
        // Make sure it's the right notification type
        if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
            return;

        // Extract the GcInfo as appropriate, working around the OpenJDK
        // GcInfo cycles/milliseconds bug
        GarbageCollectorMXBean bean = (GarbageCollectorMXBean) handback;
        GarbageCollectionNotificationInfo info = getInfo(notification);
        GcInfo gc = getGcInfo(info, bean);

        // Call the callback
        this.callback.onGC(gc);
    } catch (Exception e) {
        // swallow
    }
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:20,代码来源:XTraceGCUtils.java

示例8: setUpGCMonitoring

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
public static void setUpGCMonitoring() {
  for (java.lang.management.GarbageCollectorMXBean bean : gcbeans) {
    NotificationEmitter emitter = (NotificationEmitter) bean;
    NotificationListener listener = new NotificationListener() {
      @Override
      public void handleNotification(final Notification notification,
          final Object handback) {
        if (GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION.equals(
            notification.getType())) {
          GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(
              (CompositeData) notification.getUserData());
          long after = getTotal(info.getGcInfo().getMemoryUsageAfterGc());
          long before = getTotal(info.getGcInfo().getMemoryUsageBeforeGc());
          collectedMemory += before - after;
        }
      }
    };
    emitter.addNotificationListener(listener, null, null);
  }
}
 
开发者ID:smarr,项目名称:SOMns,代码行数:21,代码来源:ActorExecutionTrace.java

示例9: processGcEvent

import com.sun.management.GarbageCollectionNotificationInfo; //导入依赖的package包/类
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);
    }
  }
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:27,代码来源:GcLogger.java


注:本文中的com.sun.management.GarbageCollectionNotificationInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。