本文整理匯總了Java中java.lang.management.MemoryPoolMXBean.setUsageThreshold方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryPoolMXBean.setUsageThreshold方法的具體用法?Java MemoryPoolMXBean.setUsageThreshold怎麽用?Java MemoryPoolMXBean.setUsageThreshold使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.MemoryPoolMXBean
的用法示例。
在下文中一共展示了MemoryPoolMXBean.setUsageThreshold方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initCodeSizeLimits
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static void initCodeSizeLimits(int nMaxSizeMemPoolCodeCache, int nMaxSizeMemPoolPermGen)
{
// PJD remove ibm JMV
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.NON_HEAP) == 0)
{
String cs = p.getName();
if(cs.equalsIgnoreCase("Code Cache"))
p.setUsageThreshold((long)nMaxSizeMemPoolCodeCache * 1024L * 1024L);
else if(cs.equalsIgnoreCase("Perm Gen"))
p.setUsageThreshold((long)nMaxSizeMemPoolPermGen * 1024L * 1024L);
}
}
}
示例2: setMemThreshold
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
private void setMemThreshold()
{
m_bMaxPermanentHeap_MoSet = false;
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.HEAP) == 0)
{
String cs = p.getName();
if(cs.equalsIgnoreCase("Tenured gen"))
{
long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
p.setUsageThreshold(l);
m_tenuredPool = p;
}
}
}
}
示例3: runTest
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
protected void runTest() {
long headerSize = CodeCacheUtils.getHeaderSize(btype);
long allocationUnit = Math.max(0, CodeCacheUtils.MIN_ALLOCATION - headerSize);
MemoryPoolMXBean bean = btype.getMemoryPool();
long initialCount = bean.getUsageThresholdCount();
long initialSize = bean.getUsage().getUsed();
bean.setUsageThreshold(initialSize + THRESHOLD_STEP);
for (int i = 0; i < ALLOCATION_STEP - 1; i++) {
CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);
}
// Usage threshold check is triggered by GC cycle, so, call it
CodeCacheUtils.WB.fullGC();
checkUsageThresholdCount(bean, initialCount);
long filledSize = bean.getUsage().getUsed();
bean.setUsageThreshold(filledSize + THRESHOLD_STEP);
for (int i = 0; i < ALLOCATION_STEP - 1; i++) {
CodeCacheUtils.WB.allocateCodeBlob(allocationUnit, btype.id);
}
CodeCacheUtils.WB.fullGC();
checkUsageThresholdCount(bean, initialCount);
System.out.println("INFO: Case finished successfully for " + bean.getName());
}
示例4: runTest
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
protected void runTest() {
MemoryPoolMXBean bean = btype.getMemoryPool();
long initialThresholdCount = bean.getUsageThresholdCount();
long initialUsage = bean.getUsage().getUsed();
bean.setUsageThreshold(initialUsage + 1 + CodeCacheUtils.MIN_ALLOCATION);
long size = CodeCacheUtils.getHeaderSize(btype);
CodeCacheUtils.WB.allocateCodeBlob(Math.max(0, CodeCacheUtils.MIN_ALLOCATION
- size), btype.id);
// a gc cycle triggers usage threshold recalculation
CodeCacheUtils.WB.fullGC();
CodeCacheUtils.assertEQorGTE(btype, bean.getUsageThresholdCount(), initialThresholdCount,
String.format("Usage threshold was hit: %d times for %s. "
+ "Threshold value: %d with current usage: %d",
bean.getUsageThresholdCount(), bean.getName(),
bean.getUsageThreshold(), bean.getUsage().getUsed()));
System.out.println("INFO: Case finished successfully for " + bean.getName());
}
示例5: main
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static void main(String[] args) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
boolean verified = false;
for (MemoryPoolMXBean i : pools) {
if ((i.getUsage().getMax() >= TWO_G)
&& i.isUsageThresholdSupported()) {
i.setUsageThreshold(TWO_G);
if(i.getUsageThreshold() != TWO_G)
throw new RuntimeException("Usage threshold for"
+ " pool '" + i.getName() + "' is " + i.getUsageThreshold()
+ " and not equal to 2GB");
verified = true;
}
}
System.out.println("Ability to use big heap thresholds has "
+ (verified ? "" : "NOT ") + "been verified");
}
示例6: hitUsageThreshold
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
public static final void hitUsageThreshold(MemoryPoolMXBean bean,
BlobType btype) {
long initialSize = bean.getUsage().getUsed();
bean.setUsageThreshold(initialSize + 1);
long usageThresholdCount = bean.getUsageThresholdCount();
long addr = WB.allocateCodeBlob(1, btype.id);
WB.fullGC();
Utils.waitForCondition(()
-> bean.getUsageThresholdCount() == usageThresholdCount + 1);
WB.freeCodeBlob(addr);
}
示例7: runTest
import java.lang.management.MemoryPoolMXBean; //導入方法依賴的package包/類
protected void runTest() {
MemoryPoolMXBean bean = btype.getMemoryPool();
((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
addNotificationListener(this, null, null);
bean.setUsageThreshold(bean.getUsage().getUsed() + 1);
long beginTimestamp = System.currentTimeMillis();
CodeCacheUtils.WB.allocateCodeBlob(
CodeCacheUtils.ALLOCATION_SIZE, btype.id);
CodeCacheUtils.WB.fullGC();
/* waiting for expected event to be received plus double the time took
to receive expected event(for possible unexpected) and
plus 1 second in case expected event received (almost)immediately */
Utils.waitForCondition(() -> {
long currentTimestamp = System.currentTimeMillis();
int eventsCount
= counters.get(btype.getMemoryPool().getName()).get();
if (eventsCount > 0) {
if (eventsCount > 1) {
return true;
}
long timeLastEventTook
= beginTimestamp - lastEventTimestamp;
long timeoutValue
= 1000L + beginTimestamp + 3L * timeLastEventTook;
return currentTimestamp > timeoutValue;
}
return false;
});
for (BlobType bt : BlobType.getAvailable()) {
int expectedNotificationsAmount = bt.equals(btype) ? 1 : 0;
CodeCacheUtils.assertEQorGTE(btype, counters.get(bt.getMemoryPool().getName()).get(),
expectedNotificationsAmount, String.format("Unexpected "
+ "amount of notifications for pool: %s",
bt.getMemoryPool().getName()));
}
try {
((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
removeNotificationListener(this);
} catch (ListenerNotFoundException ex) {
throw new AssertionError("Can't remove notification listener", ex);
}
System.out.printf("INFO: Scenario with %s finished%n", bean.getName());
}