本文整理匯總了Java中java.lang.management.MemoryMXBean.gc方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryMXBean.gc方法的具體用法?Java MemoryMXBean.gc怎麽用?Java MemoryMXBean.gc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.MemoryMXBean
的用法示例。
在下文中一共展示了MemoryMXBean.gc方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
public static void main(String[] args)
{
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
System.out.println("Bean: " + bean);
System.out.println("Heap memory usage: "
+ bean.getHeapMemoryUsage());
System.out.println("Non-heap memory usage: "
+ bean.getNonHeapMemoryUsage());
System.out.println("Objects pending finalization: "
+ bean.getObjectPendingFinalizationCount());
System.out.println("Running garbage collector via bean...");
bean.gc();
System.out.println("Heap memory usage: "
+ bean.getHeapMemoryUsage());
System.out.println("Non-heap memory usage: "
+ bean.getNonHeapMemoryUsage());
System.out.println("Objects pending finalization: "
+ bean.getObjectPendingFinalizationCount());
boolean verbosity = bean.isVerbose();
System.out.println("Verbose memory output: " + (verbosity ? "yes" : "no"));
System.out.println("Changing verbose setting...");
bean.setVerbose(!verbosity);
System.out.println("Verbose memory output: " + (bean.isVerbose() ? "yes" : "no"));
}
示例2: main
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
public static void main(String[] args)
{
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
System.out.println("Bean: " + bean);
System.out.println("Heap memory usage: "
+ bean.getHeapMemoryUsage());
System.out.println("Non-heap memory usage: "
+ bean.getNonHeapMemoryUsage());
System.out.println("Objects pending finalization: "
+ bean.getObjectPendingFinalizationCount());
System.out.println("Running garbage collector via bean...");
bean.gc();
System.out.println("Heap memory usage: "
+ bean.getHeapMemoryUsage());
System.out.println("Non-heap memory usage: "
+ bean.getNonHeapMemoryUsage());
System.out.println("Objects pending finalization: "
+ bean.getObjectPendingFinalizationCount());
boolean verbosity = bean.isVerbose();
System.out.println("Verbose memory output: " + (verbosity ? "yes" : "no"));
System.out.println("Changing verbose setting...");
bean.setVerbose(!verbosity);
System.out.println("Verbose memory output: " + (bean.isVerbose() ? "yes" : "no"));
}
示例3: beforeEvent
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
@Override
public MonitorResult beforeEvent(MonitorResult previousResult, LoadControlCallback callback, EventMetadata metadata,
String currentSetpointId) {
if (previousResult == MonitorResult.SHED || status != MonitorStatus.ON) {
return previousResult;
}
MemoryPoolMXBean tenurePool = VMLoadControlJMXBean.getTenuredGenPool();
if (tenurePool == null) {
return previousResult;
}
MonitorResult result = tryShed(tenurePool, callback, metadata, currentSetpointId);
if (result == MonitorResult.PASSED) {
result = tryValve(tenurePool, callback, metadata, currentSetpointId);
}
if (result == MonitorResult.PASSED) {
result = tryUsageAlarm(tenurePool, callback, metadata, currentSetpointId);
}
if (result == MonitorResult.PASSED) {
result = tryCollectionUsageAlarm(tenurePool, callback, metadata, currentSetpointId);
}
if (result == MonitorResult.SHED) {
long now = System.currentTimeMillis();
if (garbageCollectionWaitTime > 0 && !thresholdExceededTimestamp.compareAndSet(0, now)) {
long ts = thresholdExceededTimestamp.get();
if (ts != 0 && now - ts > garbageCollectionWaitTime) {
thresholdExceededTimestamp.set(0);
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
memoryBean.gc();
}
}
}
return result;
}
示例4: report
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
private static void report(final String what) {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
memoryMXBean.gc();
long used = memoryMXBean.getHeapMemoryUsage().getUsed();
long delta = used - baseline;
System.out.println(what + ": " + delta + " (total=" + used + "), " + (delta / count) + "/unit");
}
示例5: setBaseLine
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
private static void setBaseLine(final String what) {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
memoryMXBean.gc();
memoryMXBean.gc();
baseline = memoryMXBean.getHeapMemoryUsage().getUsed();
System.out.println(what + ": " + baseline);
}
示例6: checkMemory
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
private static void checkMemory() {
MemoryMXBean mBean = ManagementFactory.getMemoryMXBean();
mBean.gc();
LOG.info("Build " + buildCount + " current used memory: "
+ mBean.getHeapMemoryUsage().getUsed() + " bytes");
}
示例7: reportAbsolute
import java.lang.management.MemoryMXBean; //導入方法依賴的package包/類
private static void reportAbsolute(final String what) {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
memoryMXBean.gc();
memoryMXBean.gc();
System.out.println(what + ": " + memoryMXBean.getHeapMemoryUsage().getUsed());
}