本文整理汇总了Java中java.lang.management.MemoryType类的典型用法代码示例。如果您正苦于以下问题:Java MemoryType类的具体用法?Java MemoryType怎么用?Java MemoryType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryType类属于java.lang.management包,在下文中一共展示了MemoryType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isTenured
import java.lang.management.MemoryType; //导入依赖的package包/类
/**
* Determines if the name of the memory pool MXBean provided matches a list of known tenured pool
* names.
*
* Package private for testing.
*
* @param memoryPoolMXBean The memory pool MXBean to check.
* @return True if the pool name matches a known tenured pool name, false otherwise.
*/
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
return false;
}
String name = memoryPoolMXBean.getName();
return name.equals("CMS Old Gen") // Sun Concurrent Mark Sweep GC
|| name.equals("PS Old Gen") // Sun Parallel GC
|| name.equals("G1 Old Gen") // Sun G1 GC
|| name.equals("Old Space") // BEA JRockit 1.5, 1.6 GC
|| name.equals("Tenured Gen") // Hitachi 1.5 GC
|| name.equals("Java heap") // IBM 1.5, 1.6 GC
|| name.equals("GenPauseless Old Gen") // azul C4/GPGC collector
// Allow an unknown pool name to monitor
|| (HEAP_POOL != null && name.equals(HEAP_POOL));
}
示例2: initCodeSizeLimits
import java.lang.management.MemoryType; //导入依赖的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);
}
}
}
示例3: setMemThreshold
import java.lang.management.MemoryType; //导入依赖的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;
}
}
}
}
示例4: poolSummaries
import java.lang.management.MemoryType; //导入依赖的package包/类
/**
* Returns a summary information about the memory pools.
*/
public static String poolSummaries() {
// Why ? list-archive?4273859
// How ? http://stackoverflow.com/questions/697336/how-do-i-programmatically-find-out-my-permgen-space-usage
// http://stackoverflow.com/questions/8356416/xxmaxpermsize-with-or-without-xxpermsize
StringBuilder sb = new StringBuilder();
Iterator<MemoryPoolMXBean> iter =
ManagementFactory.getMemoryPoolMXBeans().iterator();
while (iter.hasNext()) {
MemoryPoolMXBean item = iter.next();
String name = item.getName();
MemoryType type = item.getType();
MemoryUsage usage = item.getUsage();
MemoryUsage peak = item.getPeakUsage();
MemoryUsage collections = item.getCollectionUsage();
sb.append(String.format("Memory pool name: " + name
+ ", type: " + type
+ ", usage: " + usage
+ ", peak: " + peak
+ ", collections: " + collections
+ "\n"));
}
return sb.toString();
}
示例5: isTenured
import java.lang.management.MemoryType; //导入依赖的package包/类
/**
* Determines if the name of the memory pool MXBean provided matches a list of
* known tenured pool names.
*
* Package private for testing.
*
* @param memoryPoolMXBean
* The memory pool MXBean to check.
* @return True if the pool name matches a known tenured pool name, false
* otherwise.
*/
static boolean isTenured(MemoryPoolMXBean memoryPoolMXBean) {
if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
return false;
}
String name = memoryPoolMXBean.getName();
return name.equals("CMS Old Gen") // Sun Concurrent Mark Sweep GC
|| name.equals("PS Old Gen") // Sun Parallel GC
|| name.equals("G1 Old Gen") // Sun G1 GC
|| name.equals("Old Space") // BEA JRockit 1.5, 1.6 GC
|| name.equals("Tenured Gen") // Hitachi 1.5 GC
|| name.equals("Java heap") // IBM 1.5, 1.6 GC
// Allow an unknown pool name to monitor
|| (HEAP_POOL != null && name.equals(HEAP_POOL));
}
示例6: isEden
import java.lang.management.MemoryType; //导入依赖的package包/类
/**
* Determines if the name of the memory pool MXBean provided matches a list of
* known young generation pool names.
*
* @param memoryPoolMXBean
* The memory pool MXBean to check.
* @return True if the pool name matches a known young generation pool name,
* false otherwise.
*/
static boolean isEden(MemoryPoolMXBean memoryPoolMXBean) {
if (memoryPoolMXBean.getType() != MemoryType.HEAP) {
return false;
}
String name = memoryPoolMXBean.getName();
return name.equals("Par Eden Space") // Oracle ParNew with Concurrent Mark Sweep GC
|| name.equals("PS Eden Space") // Oracle Parallel GC
|| name.equals("G1 Eden") // Oracle G1 GC
//|| name.equals("Nursery") // BEA JRockit 1.5, 1.6 GC
|| name.equals("Eden Space") // Hitachi 1.5 GC
// Allow an unknown pool name to monitor
|| (HEAP_EDEN_POOL != null && name.equals(HEAP_EDEN_POOL));
}
示例7: getMemoryBean
import java.lang.management.MemoryType; //导入依赖的package包/类
private static MemoryPoolMXBean getMemoryBean(){
System.gc();
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
long curMax = 0;
MemoryPoolMXBean heap = null;
for (MemoryPoolMXBean pool : pools) {
if (pool.getType() != MemoryType.HEAP) {
continue;
}
MemoryUsage memusage = pool.getUsage();
long max = memusage.getMax();
if(max > curMax)
heap = pool;
}
return heap;
}
示例8: getMemoryPoolStatsAsString
import java.lang.management.MemoryType; //导入依赖的package包/类
/**
* Gets the memory pool statistics from the JVM.
*
* @param poolBeans The collection of memory pool beans.
* @return A string denoting the names and sizes of the memory pools.
*/
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
int count = 0;
for (MemoryPoolMXBean bean : poolBeans) {
if (bean.getType() == MemoryType.NON_HEAP) {
if (count > 0) {
bld.append(", ");
}
count++;
MemoryUsage usage = bean.getUsage();
long used = usage.getUsed() >> 20;
long committed = usage.getCommitted() >> 20;
long max = usage.getMax() >> 20;
bld.append('[').append(bean.getName()).append(": ");
bld.append(used).append('/').append(committed).append('/').append(max);
bld.append(" MB (used/committed/max)]");
}
}
return bld.toString();
}
示例9: reportPeakMemoryUsage
import java.lang.management.MemoryType; //导入依赖的package包/类
public static void reportPeakMemoryUsage() {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
long totalHeap = 0;
long totalNonHeap = 0;
long gcTime = 0;
for (MemoryPoolMXBean memoryPoolMXBean : pools) {
long peakUsed = memoryPoolMXBean.getPeakUsage().getUsed();
if (memoryPoolMXBean.getType() == MemoryType.HEAP) {
totalHeap += peakUsed;
} else if (memoryPoolMXBean.getType() == MemoryType.NON_HEAP) {
totalNonHeap += peakUsed;
}
}
for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
gcTime += garbageCollectorMXBean.getCollectionTime();
}
VM.println("[Memstat] Heap: " + totalHeap + "B\tNonHeap: " + totalNonHeap
+ "B\tCollected: " + collectedMemory + "B\tGC-Time: " + gcTime + "ms");
}
示例10: init
import java.lang.management.MemoryType; //导入依赖的package包/类
public synchronized static void init(ConfigServer cs){
if(init) return;
// set level
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
types.put(pool.getName(), pool.getType());
// I don't know whether this approach is better, or whether
// we should rather check for the pool name "Tenured Gen"?
if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
long maxMemory = pool.getUsage().getMax();
long warningThreshold = (long) (maxMemory * 0.9);
//long warningThreshold = maxMemory -(10*1024*1024);
pool.setUsageThreshold(warningThreshold);
}
}
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
NotificationEmitter emitter = (NotificationEmitter) mbean;
MemoryNotificationListener listener = new MemoryNotificationListener(types);
emitter.addNotificationListener(listener, null, cs);
init=true;
}
示例11: getMemoryUsageAsStruct
import java.lang.management.MemoryType; //导入依赖的package包/类
public static Struct getMemoryUsageAsStruct(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
long used=0,max=0,init=0;
while(it.hasNext()){
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if((type==MEMORY_TYPE_HEAP && _type==MemoryType.HEAP) || (type==MEMORY_TYPE_NON_HEAP && _type==MemoryType.NON_HEAP)){
used+=usage.getUsed();
max+=usage.getMax();
init+=usage.getInit();
}
}
Struct sct=new StructImpl();
sct.setEL(KeyConstants._used, Caster.toDouble(used));
sct.setEL(KeyConstants._max, Caster.toDouble(max));
sct.setEL(KeyConstants._init, Caster.toDouble(init));
sct.setEL(KeyImpl.init("available"), Caster.toDouble(max-used));
return sct;
}
示例12: getMemoryUsageCompact
import java.lang.management.MemoryType; //导入依赖的package包/类
public static Struct getMemoryUsageCompact(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
Struct sct=new StructImpl();
while(it.hasNext()){
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if(type==MEMORY_TYPE_HEAP && _type!=MemoryType.HEAP)continue;
if(type==MEMORY_TYPE_NON_HEAP && _type!=MemoryType.NON_HEAP)continue;
double d=((int)(100D/usage.getMax()*usage.getUsed()))/100D;
sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
}
return sct;
}
示例13: getMemoryUsageAsStruct
import java.lang.management.MemoryType; //导入依赖的package包/类
public static Struct getMemoryUsageAsStruct(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
long used = 0, max = 0, init = 0;
while(it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if((type == MEMORY_TYPE_HEAP && _type == MemoryType.HEAP) || (type == MEMORY_TYPE_NON_HEAP && _type == MemoryType.NON_HEAP)) {
used += usage.getUsed();
max += usage.getMax();
init += usage.getInit();
}
}
Struct sct = new StructImpl();
sct.setEL(KeyConstants._used, Caster.toDouble(used));
sct.setEL(KeyConstants._max, Caster.toDouble(max));
sct.setEL(KeyConstants._init, Caster.toDouble(init));
sct.setEL(KeyImpl.init("available"), Caster.toDouble(max - used));
return sct;
}
示例14: getMemoryUsageCompact
import java.lang.management.MemoryType; //导入依赖的package包/类
public static Struct getMemoryUsageCompact(int type) {
java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
Iterator<MemoryPoolMXBean> it = manager.iterator();
MemoryPoolMXBean bean;
MemoryUsage usage;
MemoryType _type;
Struct sct = new StructImpl();
while(it.hasNext()) {
bean = it.next();
usage = bean.getUsage();
_type = bean.getType();
if(type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP)
continue;
if(type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP)
continue;
double d = ((int)(100D / usage.getMax() * usage.getUsed())) / 100D;
sct.setEL(KeyImpl.init(bean.getName()), Caster.toDouble(d));
}
return sct;
}
示例15: testReadWriteObject
import java.lang.management.MemoryType; //导入依赖的package包/类
public void testReadWriteObject() throws Exception {
checkBasicReadWriteObject(Boolean.TRUE, "java.lang.Boolean:true\n");
checkBasicReadWriteObject(Byte.valueOf("1"), "java.lang.Byte:1\n");
checkBasicReadWriteObject(Double.valueOf("1.0"), "java.lang.Double:1.0\n");
checkBasicReadWriteObject(Float.valueOf("1.0"), "java.lang.Float:1.0\n");
checkBasicReadWriteObject(Integer.valueOf("1"), "java.lang.Integer:1\n");
checkBasicReadWriteObject(Long.valueOf("1"), "java.lang.Long:1\n");
checkBasicReadWriteObject(Short.valueOf("1"), "java.lang.Short:1\n");
checkBasicReadWriteObject(BigDecimal.valueOf(500.5), "java.math.BigDecimal:500.5\n");
checkBasicReadWriteObject(BigInteger.valueOf(500), "java.math.BigInteger:500\n");
checkBasicReadWriteObject("1", "java.lang.String:1\n");
checkBasicReadObject(Arrays.asList(new Object[] {"a", UtilMisc.toMap("b", Long.valueOf(1))}), "[\n \"a\",\n {\n \"b\": 1\n }\n]\n");
checkBasicReadWriteObject(MemoryType.HEAP, "java.lang.management.MemoryType:HEAP\n");
checkBasicReadWriteObject(MemoryType.NON_HEAP, "java.lang.management.MemoryType:NON_HEAP\n");
checkBasicReadWriteObject(UtilIO.UTF8, "java.nio.charset.Charset:UTF-8\n");
checkBasicReadWriteObject(InetAddress.getByAddress("localhost", new byte[] {127, 0, 0, 1}), "java.net.InetAddress:localhost\n");
//checkBasicReadWriteObject(Pattern.compile("^([a-z]{3}.*?):$"), "java.util.regex.Pattern:^([a-z]{3}.*?):$\n");
checkBasicReadWriteObject(Time.valueOf("12:34:56"), "java.sql.Time:12:34:56\n");
//checkBasicReadWriteObject(new Timestamp(1234567890), "java.sql.Timestamp:1234567890 00:00:00\n");
//checkBasicReadWriteObject(new java.util.Date(1234567890), "java.util.Date:1234567890\n");
checkBasicReadWriteObject(UUID.fromString("c3241927-9f77-43e1-be16-bd71d245ef64"), "java.util.UUID:c3241927-9f77-43e1-be16-bd71d245ef64\n");
checkBasicReadWriteObject(TimeZone.getTimeZone("America/Chicago"), "java.util.TimeZone:America/Chicago\n");
checkBasicReadWriteObject(new SimpleDateFormat("MM/dd/yyyy hh:mm a"), "java.text.SimpleDateFormat:MM/dd/yyyy hh:mm a\n");
checkBasicReadWriteObject(new Locale("en", "us"), "java.util.Locale:en_US\n");
}