本文整理汇总了Java中com.sun.management.GarbageCollectionNotificationInfo.from方法的典型用法代码示例。如果您正苦于以下问题:Java GarbageCollectionNotificationInfo.from方法的具体用法?Java GarbageCollectionNotificationInfo.from怎么用?Java GarbageCollectionNotificationInfo.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.management.GarbageCollectionNotificationInfo
的用法示例。
在下文中一共展示了GarbageCollectionNotificationInfo.from方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
}
}
}
示例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)) {
listenerInvoked.put(((ObjectName)notif.getSource()).getCanonicalName(),true);
count++;
if(count >= number) {
synchronizer.notify();
}
}
}
}
}
示例4: 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());
}
}
示例5: 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);
}
}
示例6: handleNotification
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public void handleNotification(Notification notification, Object ref) {
final String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
processGcEvent(info);
}
}
示例7: enableGarbageCollectionLogging
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public static void enableGarbageCollectionLogging()
{
//get all the GarbageCollectorMXBeans - there's one for each heap generation
//so probably two - the old generation and young generation
List<java.lang.management.GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
//Install a notifcation handler for each bean
for (GarbageCollectorMXBean gcbean : gcbeans)
{
System.out.println(gcbean);
NotificationEmitter emitter = (NotificationEmitter) gcbean;
//use an anonymously generated listener for this example
// - proper code should really use a named class
NotificationListener listener = new NotificationListener()
{
//keep a count of the total time spent in GCs
long totalGcDuration = 0;
//implement the notifier callback handler
@Override
public void handleNotification(Notification notification, Object handback)
{
//we only handle GARBAGE_COLLECTION_NOTIFICATION notifications here
if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
//get the information associated with this notification
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
String gctype = info.getGcAction();
if ("end of minor GC".equals(gctype))
gctype = "Young Gen GC";
else if ("end of major GC".equals(gctype))
gctype = "Old Gen GC";
StringBuilder sb = new StringBuilder();
sb.append("**************************\nGarbage Collector invoked!\n**************************\n");
sb.append("GC Type: ").append(gctype).append("\n");
//sb.append("ID: ").append(info.getGcInfo().getId()).append("\n");
sb.append("Cause: ").append(info.getGcCause()).append("\n");
sb.append("Duration: ").append(info.getGcInfo().getDuration()).append(" ms\n");
/*//Get the information about each memory space, and pretty print it
Map<String, MemoryUsage> membefore = info.getGcInfo().getMemoryUsageBeforeGc();
Map<String, MemoryUsage> mem = info.getGcInfo().getMemoryUsageAfterGc();
for (Entry<String, MemoryUsage> entry : mem.entrySet())
{
String name = entry.getKey();
MemoryUsage memdetail = entry.getValue();
long memInit = memdetail.getInit();
long memCommitted = memdetail.getCommitted();
long memMax = memdetail.getMax();
long memUsed = memdetail.getUsed();
MemoryUsage before = membefore.get(name);
long beforepercent = ((before.getUsed()*1000L)/before.getCommitted());
long percent = ((memUsed*1000L)/before.getCommitted()); //>100% when it gets expanded
sb.append(name + (memCommitted==memMax?"(fully expanded)":"(still expandable)") +"used: "+(beforepercent/10)+"."+(beforepercent%10)+"%->"+(percent/10)+"."+(percent%10)+"%("+((memUsed/1048576)+1)+"MB) / \n");
}*/
totalGcDuration += info.getGcInfo().getDuration();
long percent = totalGcDuration*1000L/info.getGcInfo().getEndTime();
sb.append("GC cumulated overhead "+(percent/10)+"."+(percent%10)+"%");
Debug.log(sb.append("\n").toString());
}
}
};
//Add the listener
emitter.addNotificationListener(listener, null, null);
}
}
示例8: installGCMonitoring
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public static void installGCMonitoring()
{
//get all the GarbageCollectorMXBeans - there's one for each heap generation
//so probably two - the old generation and young generation
List<java.lang.management.GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
//Install a notifcation handler for each bean
for (GarbageCollectorMXBean gcbean : gcbeans)
{
System.out.println(gcbean);
NotificationEmitter emitter = (NotificationEmitter) gcbean;
//use an anonymously generated listener for this example
// - proper code should really use a named class
NotificationListener listener = new NotificationListener()
{
//keep a count of the total time spent in GCs
long totalGcDuration = 0;
//implement the notifier callback handler
@Override
public void handleNotification(Notification notification, Object handback)
{
//we only handle GARBAGE_COLLECTION_NOTIFICATION notifications here
if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
//get the information associated with this notification
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
String gctype = info.getGcAction();
if ("end of minor GC".equals(gctype))
gctype = "Young Gen GC";
else if ("end of major GC".equals(gctype))
gctype = "Old Gen GC";
StringBuilder sb = new StringBuilder();
sb.append("**************************\nGarbage Collector invoked!\n**************************\n");
sb.append("GC Type: ").append(gctype).append("\n");
sb.append("ID: ").append(info.getGcInfo().getId()).append("\n");
sb.append("Cause: ").append(info.getGcCause()).append("\n");
sb.append("Duration: ").append(info.getGcInfo().getDuration()).append(" ms\n");
/*//Get the information about each memory space, and pretty print it
Map<String, MemoryUsage> membefore = info.getGcInfo().getMemoryUsageBeforeGc();
Map<String, MemoryUsage> mem = info.getGcInfo().getMemoryUsageAfterGc();
for (Entry<String, MemoryUsage> entry : mem.entrySet())
{
String name = entry.getKey();
MemoryUsage memdetail = entry.getValue();
long memInit = memdetail.getInit();
long memCommitted = memdetail.getCommitted();
long memMax = memdetail.getMax();
long memUsed = memdetail.getUsed();
MemoryUsage before = membefore.get(name);
long beforepercent = ((before.getUsed()*1000L)/before.getCommitted());
long percent = ((memUsed*1000L)/before.getCommitted()); //>100% when it gets expanded
sb.append(name + (memCommitted==memMax?"(fully expanded)":"(still expandable)") +"used: "+(beforepercent/10)+"."+(beforepercent%10)+"%->"+(percent/10)+"."+(percent%10)+"%("+((memUsed/1048576)+1)+"MB) / \n");
}*/
totalGcDuration += info.getGcInfo().getDuration();
long percent = totalGcDuration*1000L/info.getGcInfo().getEndTime();
sb.append("GC cumulated overhead "+(percent/10)+"."+(percent%10)+"%");
Debug.log(sb.append("\n").toString());
}
}
};
//Add the listener
emitter.addNotificationListener(listener, null, null);
}
}
示例9: getInfo
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
private GarbageCollectionNotificationInfo getInfo(Notification notification) {
CompositeData cd = (CompositeData) notification.getUserData();
return GarbageCollectionNotificationInfo.from(cd);
}
示例10: getInfo
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
private static GarbageCollectionNotificationInfo getInfo(Notification notification) {
CompositeData cd = (CompositeData) notification.getUserData();
return GarbageCollectionNotificationInfo.from(cd);
}
示例11: handleNotification
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public void handleNotification(Notification notification, Object handback)
{
String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
// retrieve the garbage collection notification information
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
long duration = info.getGcInfo().getDuration();
StringBuilder sb = new StringBuilder();
sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms. ");
long bytes = 0;
List<String> keys = new ArrayList<>(info.getGcInfo().getMemoryUsageBeforeGc().keySet());
Collections.sort(keys);
for (String key : keys)
{
MemoryUsage before = info.getGcInfo().getMemoryUsageBeforeGc().get(key);
MemoryUsage after = info.getGcInfo().getMemoryUsageAfterGc().get(key);
if (after != null && after.getUsed() != before.getUsed())
{
sb.append(key).append(": ").append(before.getUsed());
sb.append(" -> ");
sb.append(after.getUsed());
if (!key.equals(keys.get(keys.size() - 1)))
sb.append("; ");
bytes += before.getUsed() - after.getUsed();
}
}
while (true)
{
State prev = state.get();
if (state.compareAndSet(prev, new State(duration, bytes, prev)))
break;
}
String st = sb.toString();
if (duration > MIN_LOG_DURATION)
logger.info(st);
else if (logger.isDebugEnabled())
logger.debug(st);
if (duration > MIN_LOG_DURATION_TPSTATS)
StatusLogger.log();
// if we just finished a full collection and we're still using a lot of memory, try to reduce the pressure
if (info.getGcName().equals("ConcurrentMarkSweep"))
SSTableDeletingTask.rescheduleFailedTasks();
}
}
示例12: handleNotification
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public void handleNotification(final Notification notification, final Object handback)
{
String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
// retrieve the garbage collection notification information
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
String gcName = info.getGcName();
GcInfo gcInfo = info.getGcInfo();
long duration = gcInfo.getDuration();
/*
* The duration supplied in the notification info includes more than just
* application stopped time for concurrent GCs. Try and do a better job coming up with a good stopped time
* value by asking for and tracking cumulative time spent blocked in GC.
*/
GCState gcState = gcStates.get(gcName);
if (gcState.assumeGCIsPartiallyConcurrent)
{
long previousTotal = gcState.lastGcTotalDuration;
long total = gcState.gcBean.getCollectionTime();
gcState.lastGcTotalDuration = total;
duration = total - previousTotal; // may be zero for a really fast collection
}
StringBuilder sb = new StringBuilder();
sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms. ");
long bytes = 0;
Map<String, MemoryUsage> beforeMemoryUsage = gcInfo.getMemoryUsageBeforeGc();
Map<String, MemoryUsage> afterMemoryUsage = gcInfo.getMemoryUsageAfterGc();
for (String key : gcState.keys(info))
{
MemoryUsage before = beforeMemoryUsage.get(key);
MemoryUsage after = afterMemoryUsage.get(key);
if (after != null && after.getUsed() != before.getUsed())
{
sb.append(key).append(": ").append(before.getUsed());
sb.append(" -> ");
sb.append(after.getUsed());
if (!key.equals(gcState.keys[gcState.keys.length - 1]))
sb.append("; ");
bytes += before.getUsed() - after.getUsed();
}
}
while (true)
{
State prev = state.get();
if (state.compareAndSet(prev, new State(duration, bytes, prev)))
break;
}
String st = sb.toString();
if (GC_WARN_THRESHOLD_IN_MS != 0 && duration > GC_WARN_THRESHOLD_IN_MS)
logger.warn(st);
else if (duration > MIN_LOG_DURATION)
logger.info(st);
else if (logger.isTraceEnabled())
logger.trace(st);
if (duration > STAT_THRESHOLD)
StatusLogger.log();
// if we just finished an old gen collection and we're still using a lot of memory, try to reduce the pressure
if (gcState.assumeGCIsOldGen)
LifecycleTransaction.rescheduleFailedDeletions();
}
}
示例13: main
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
public static void main(String[] args) {
OperatingSystemMXBean mxBean = ManagementFactory.getOperatingSystemMXBean();
System.out.println(mxBean.getSystemLoadAverage());
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
System.out.println(threadMXBean.getAllThreadIds());
System.out.println(threadMXBean.getCurrentThreadCpuTime());
System.out.println(threadMXBean.getCurrentThreadUserTime());
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
System.out.println(memoryMXBean.getHeapMemoryUsage());
System.out.println(memoryMXBean.getNonHeapMemoryUsage());
System.out.println(memoryMXBean.getObjectPendingFinalizationCount());
for (MemoryManagerMXBean memoryManagerMXBean : ManagementFactory.getMemoryManagerMXBeans()) {
System.out.println(memoryManagerMXBean.getName());
}
NotificationListener notificationListener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
if (notification.getType().equals(GarbageCollectionNotificationInfo
.GARBAGE_COLLECTION_NOTIFICATION)) {
GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from
((CompositeData) notification.getUserData());
System.out.println(gcInfo.getGcName());
System.out.println(gcInfo.getGcInfo().getMemoryUsageBeforeGc());
System.out.println(gcInfo.getGcInfo().getMemoryUsageAfterGc());
for (MemoryUsage memoryUsage : gcInfo.getGcInfo().getMemoryUsageBeforeGc().values()) {
System.out.println(memoryUsage.getUsed());
}
}
}
};
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
NotificationEmitter emitter = (NotificationEmitter) gcBean;
emitter.addNotificationListener(notificationListener, null, null);
}
while (true) {
}
}
示例14: handleNotification
import com.sun.management.GarbageCollectionNotificationInfo; //导入方法依赖的package包/类
@Override
public void handleNotification(Notification notification, Object handback) {
if (!notification
.getType()
.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
return;
}
GarbageCollectionNotificationInfo info =
GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
Map<String, MemoryUsage> spaces = info.getGcInfo().getMemoryUsageAfterGc();
for (Map.Entry<String, MemoryUsage> entry : spaces.entrySet()) {
if (isTenuredSpace(entry.getKey())) {
MemoryUsage space = entry.getValue();
if (space.getMax() == 0) {
// The CMS collector sometimes passes us nonsense stats.
continue;
}
long percentUsed = 100 * space.getUsed() / space.getMax();
if (percentUsed > occupiedHeapPercentageThreshold) {
if (info.getGcCause().equals("System.gc()") && !throwingOom.getAndSet(true)) {
// Assume we got here from a GC initiated by the other branch.
String exitMsg =
String.format(
"RetainedHeapLimiter forcing exit due to GC thrashing: tenured space "
+ "%s out of %s (>%s%%) occupied after back-to-back full GCs",
space.getUsed(),
space.getMax(),
occupiedHeapPercentageThreshold);
System.err.println(exitMsg);
logger.info(exitMsg);
// Exits the runtime.
BugReport.handleCrash(new OutOfMemoryError(exitMsg));
} else if (System.currentTimeMillis() - lastTriggeredGcInMilliseconds
> MIN_TIME_BETWEEN_TRIGGERED_GC_MILLISECONDS) {
logger.info(
"Triggering a full GC with "
+ space.getUsed()
+ " out of "
+ space.getMax()
+ " used");
// Force a full stop-the-world GC and see if it can get us below the threshold.
System.gc();
lastTriggeredGcInMilliseconds = System.currentTimeMillis();
}
}
}
}
}