本文整理汇总了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);
}
}
示例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);
}
示例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();
}
}
}
}
}
示例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();
}
}
}
}
}
示例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);
}
示例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());
}
}
示例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
}
}
示例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);
}
}
示例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);
}
}
}