use of java.lang.management.MemoryPoolMXBean in project jekejeke-devel by jburse.
the class HotspotUsage method addListener.
/**
* <p>Add a notification listener.</p>
* <p>If this is the first listener save and init the threshold.</p>
*
* @param listener The listener.
*/
public final void addListener(NotificationListener listener) {
synchronized (thresholds) {
if (count == 0) {
Iterator<MemoryPoolMXBean> pool = ManagementFactory.getMemoryPoolMXBeans().iterator();
while (pool.hasNext()) {
MemoryPoolMXBean pbean = pool.next();
if (pbean.isUsageThresholdSupported()) {
long threshold = pbean.getUsageThreshold();
thresholds.put(pbean.getName(), Long.valueOf(threshold));
threshold = pbean.getUsage().getMax() * 85 / 100;
pbean.setUsageThreshold(threshold);
}
}
}
count++;
}
NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
emitter.addNotificationListener(listener, null, null);
}
use of java.lang.management.MemoryPoolMXBean in project jekejeke-devel by jburse.
the class HotspotUsage method removeListener.
/**
* <p>Remove a notificatio listener.</p>
* <p>If this is the last listener restore the threshold.</p>
*
* @param listener The listener.
*/
public final void removeListener(NotificationListener listener) {
NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(listener, null, null);
} catch (ListenerNotFoundException e) {
throw new RuntimeException(e);
}
synchronized (thresholds) {
count--;
if (count == 0) {
Iterator<MemoryPoolMXBean> pool = ManagementFactory.getMemoryPoolMXBeans().iterator();
while (pool.hasNext()) {
MemoryPoolMXBean pbean = pool.next();
if (pbean.isUsageThresholdSupported()) {
long threshold = thresholds.get(pbean.getName()).longValue();
pbean.setUsageThreshold(threshold);
}
}
}
}
}
use of java.lang.management.MemoryPoolMXBean in project OpenOLAT by OpenOLAT.
the class MemoryWebService method createMemoryPools.
private MemoryPoolVO[] createMemoryPools() {
List<MemoryPoolMXBean> memoryPool = ManagementFactory.getMemoryPoolMXBeans();
MemoryPoolVO[] voes = new MemoryPoolVO[memoryPool.size()];
int count = 0;
for (MemoryPoolMXBean bean : memoryPool) {
if (bean.isValid()) {
voes[count++] = new MemoryPoolVO(bean);
}
}
return voes;
}
use of java.lang.management.MemoryPoolMXBean in project btrace by btraceio.
the class BTraceRuntime method getMemoryPoolUsage.
static String getMemoryPoolUsage(String poolFormat) {
if (poolFormat == null) {
poolFormat = "%1$s;%2$d;%3$d;%4$d;%5$d";
}
Object[][] poolOutput = new Object[memPoolList.size()][5];
StringBuilder membuffer = new StringBuilder();
for (int i = 0; i < memPoolList.size(); i++) {
MemoryPoolMXBean memPool = memPoolList.get(i);
poolOutput[i][0] = memPool.getName();
poolOutput[i][1] = memPool.getUsage().getMax();
poolOutput[i][2] = memPool.getUsage().getUsed();
poolOutput[i][3] = memPool.getUsage().getCommitted();
poolOutput[i][4] = memPool.getUsage().getInit();
}
for (Object[] memPoolOutput : poolOutput) {
membuffer.append(String.format(poolFormat, memPoolOutput)).append("\n");
}
return membuffer.toString();
}
use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.
the class TestMemoryPoolMXBean method testBadSetAttribute.
@Test
public final void testBadSetAttribute() {
MemoryPoolMXBean testImpl = testBean;
// Let's try and set some non-writable attributes.
Attribute attr = new Attribute("UsageThresholdCount", new Long(25));
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception.");
} catch (Exception e) {
logger.debug("testBadSetAttribute exception:" + e.getClass().getName() + ", errMessage=" + e.getMessage());
AssertJUnit.assertTrue(e instanceof AttributeNotFoundException);
}
// Try and set the UsageThreshold attribute with an incorrect
// type.
attr = new Attribute("UsageThreshold", "rubbish");
try {
mbs.setAttribute(objName, attr);
Assert.fail("Unreacheable code: should have thrown an exception");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof InvalidAttributeValueException);
}
}
Aggregations