use of java.lang.management.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getFreePermGenSpaceSize.
public static long getFreePermGenSpaceSize() {
MemoryUsage mu = getPermGenSpaceSize(null);
if (mu == null)
return -1;
long max = mu.getMax();
long used = mu.getUsed();
if (max < 0 || used < 0)
return -1;
return max - used;
}
use of java.lang.management.MemoryUsage in project Lucee by lucee.
the class MacAddressWrap method getFreePermGenSpacePromille.
public static int getFreePermGenSpacePromille() {
MemoryUsage mu = getPermGenSpaceSize(null);
if (mu == null)
return -1;
long max = mu.getMax();
long used = mu.getUsed();
if (max < 0 || used < 0)
return -1;
return (int) (1000L - (1000L * used / max));
}
use of java.lang.management.MemoryUsage in project knime-core by knime.
the class MemoryService method isMemoryLow.
/**
* This is a stateful method return true in the low memory condition. Note,
* this method only returns true at most once between two garbage
* collections.
*
* @return True if memory is low.
*/
public boolean isMemoryLow() {
if (m_waitForNextGC) {
long thisCount = null != m_memPool ? m_gcBean.iterator().next().getCollectionCount() : Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
if (thisCount == m_lastCount) {
return false;
} else {
m_waitForNextGC = false;
}
}
MemoryUsage usage = null;
if (m_useCollectionUsage) {
usage = m_memPool.getCollectionUsage();
}
if (null == usage && null != m_memPool) {
usage = m_memPool.getUsage();
}
if (null != usage) {
boolean memoryIsLow = usage.getUsed() > m_threshold;
if (memoryIsLow) {
m_waitForNextGC = true;
m_lastCount = m_gcBean.iterator().next().getCollectionCount();
return true;
} else {
return false;
}
} else {
long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
boolean memoryIsLow = used > m_threshold;
if (memoryIsLow) {
m_waitForNextGC = true;
m_lastCount = used;
return true;
} else {
return false;
}
}
}
use of java.lang.management.MemoryUsage in project Payara by payara.
the class MemoryReporter method getMemoryPoolReport.
private String getMemoryPoolReport() {
final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder());
final long millis = rmbean.getUptime();
final String uptime = sm.getString("uptime", JVMInformationCollector.millis2HoursMinutesSeconds(millis));
sb.append(uptime);
for (final MemoryPoolMXBean m : pools) {
final String n = m.getName();
sb.append(sm.getString("memory.pool.name", n));
MemoryUsage mu = m.getUsage();
sb.append(mu2String(mu));
}
return (sb.toString());
}
use of java.lang.management.MemoryUsage in project Payara by payara.
the class HeapMemoryUsageHealthCheck method doCheck.
@Override
public HealthCheckResult doCheck() {
HealthCheckResult result = new HealthCheckResult();
MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
MemoryUsage heap = memBean.getHeapMemoryUsage();
String heapValueText = String.format("heap: init: %s, used: %s, committed: %s, max.: %s", prettyPrintBytes(heap.getInit()), prettyPrintBytes(heap.getUsed()), prettyPrintBytes(heap.getCommitted()), prettyPrintBytes(heap.getMax()));
Double percentage = calculatePercentage(heap);
result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), heapValueText + "heap%: " + percentage + "%"));
return result;
}
Aggregations