本文整理汇总了Java中com.sun.management.HotSpotDiagnosticMXBean类的典型用法代码示例。如果您正苦于以下问题:Java HotSpotDiagnosticMXBean类的具体用法?Java HotSpotDiagnosticMXBean怎么用?Java HotSpotDiagnosticMXBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HotSpotDiagnosticMXBean类属于com.sun.management包,在下文中一共展示了HotSpotDiagnosticMXBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkVMOption
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
VMOption option = mbean.getVMOption(PRINT_GC_DETAILS);
if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
throw new RuntimeException("Unexpected value: " +
option.getValue() + " expected: " + EXPECTED_VALUE);
}
boolean iae = false;
try {
mbean.getVMOption(BAD_OPTION);
} catch (IllegalArgumentException e) {
iae = true;
}
if (!iae) {
throw new RuntimeException("Invalid VM Option" +
" was not detected");
}
}
示例2: test
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private final void test() {
System.gc();
MemoryUsagePrinter.printMemoryUsage("init");
allocate();
MemoryUsagePrinter.printMemoryUsage("allocated");
MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
free();
MemoryUsagePrinter.printMemoryUsage("free");
MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
"committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
+ "%s = %s%n%s = %s",
MIN_FREE_RATIO_FLAG_NAME,
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
.getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
MAX_FREE_RATIO_FLAG_NAME,
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
.getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
));
}
示例3: test
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private final void test() {
System.gc();
MemoryUsagePrinter.printMemoryUsage("init");
eat();
MemoryUsagePrinter.printMemoryUsage("eaten");
MemoryUsage muFull = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
free();
MemoryUsagePrinter.printMemoryUsage("free");
MemoryUsage muFree = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
assertLessThan(muFree.getCommitted(), muFull.getCommitted(), String.format(
"committed free heap size is not less than committed full heap size, heap hasn't been shrunk?%n"
+ "%s = %s%n%s = %s",
MIN_FREE_RATIO_FLAG_NAME,
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
.getVMOption(MIN_FREE_RATIO_FLAG_NAME).getValue(),
MAX_FREE_RATIO_FLAG_NAME,
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class)
.getVMOption(MAX_FREE_RATIO_FLAG_NAME).getValue()
));
}
示例4: main
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public static void main(String... args) throws Exception {
MBeanServerConnection msc = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean mxbean =
ManagementFactory.getPlatformMXBean(msc, HotSpotDiagnosticMXBean.class);
String[] signatures = new String[] {
String.class.getName()
};
Object obj = msc.invoke(mxbean.getObjectName(), "getVMOption",
new String[] { "PrintVMOptions"}, signatures);
CompositeData data = (CompositeData)obj;
validateType(data);
VMOption option = mxbean.getVMOption("PrintVMOptions");
VMOption o = VMOption.from(data);
assertEquals(option, o);
}
示例5: checkVMOption
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
VMOption option = mbean.getVMOption(HEAP_DUMP_ON_OOM);
if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
throw new RuntimeException("Unexpected value: " +
option.getValue() + " expected: " + EXPECTED_VALUE);
}
boolean iae = false;
try {
mbean.getVMOption(BAD_OPTION);
} catch (IllegalArgumentException e) {
iae = true;
}
if (!iae) {
throw new RuntimeException("Invalid VM Option" +
" was not detected");
}
}
示例6: getHotSpotMXBean
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private static HotSpotDiagnosticMXBean getHotSpotMXBean() {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<HotSpotDiagnosticMXBean>() {
public HotSpotDiagnosticMXBean run() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> s = server.queryNames(new ObjectName(HOT_SPOT_BEAN_NAME), null);
Iterator<ObjectName> itr = s.iterator();
if (itr.hasNext()) {
ObjectName name = itr.next();
HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,
name.toString(), HotSpotDiagnosticMXBean.class);
return bean;
} else {
return null;
}
}
});
} catch (Exception e) {
LOGGER.error("getHotSpotMXBean Error!", e);
return null;
}
}
示例7: main
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public static void main(String[] args) {
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for (BufferPoolMXBean pool:pools) {
System.out.println(String.format(
"%s %d/%d",
pool.getName(),
pool.getMemoryUsed(),
pool.getTotalCapacity()));
}
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
for (String arg:RuntimemxBean.getInputArguments()) {
System.out.println(arg);
}
HotSpotDiagnosticMXBean hsdiag = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
for (VMOption i:hsdiag.getDiagnosticOptions()) {
System.out.println(i.getName() + ":" + i.getValue());
}
System.out.println(hsdiag.getVMOption("MaxDirectMemorySize"));
System.out.println(sun.misc.VM.maxDirectMemory());
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(ByteBuffer.allocateDirect(1000000000));
System.out.println(getDirectMemoryUsed());
}
示例8: dumpTo
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
/**
* Dumps the heap to the outputFile file in the same format as the hprof heap dump.
* If this method is called remotely from another process, the heap dump output is written to a file named outputFile on the machine where the target VM is running. If outputFile is a relative path, it is relative to the working directory where the target VM was started.
* @param res Resource to write the .hprof file.
* @param live if true dump only live objects i.e. objects that are reachable from others
* @throws IOException
*/
public static void dumpTo(Resource res, boolean live) throws IOException {
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean mxbean = ManagementFactory.newPlatformMXBeanProxy( mbserver, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class );
String path;
Resource tmp=null;
if(res instanceof FileResource) path=res.getAbsolutePath();
else {
tmp=SystemUtil.getTempFile("hprof",false);
path=tmp.getAbsolutePath();
}
try{
// it only
mxbean.dumpHeap(path, live);
}
finally{
if(tmp!=null && tmp.exists()){
tmp.moveTo(res);
}
}
}
示例9: fillMemory
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private static void fillMemory() throws ParseException, IOException {
setTimeZone("Asia/Seoul");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(timeZoneCache);
Date begin = getDay(sdf.parse("1900-01-01"));
Date end = getDay(sdf.parse("2101-01-01"));
Calendar c = Calendar.getInstance(timeZoneCache);
c.setTime(begin);
c.set(Calendar.MILLISECOND, 0);
while (c.getTime().before(end)) {
getDay(c.getTime());
c.add(Calendar.SECOND, 10);
if (c.getTime().getTime() % 86400000L == 0)
System.out.println(sdf.format(c.getTime()));
}
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean bean =
ManagementFactory.newPlatformMXBeanProxy(platformMBeanServer,
"com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
bean.dumpHeap("E:\\w\\araqne\\CalendarDump.hprof", true);
}
示例10: dumpHeap
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public static boolean dumpHeap(String fileName, boolean live) {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
logger.fine("Taking heap dump..");
HotSpotDiagnosticMXBean hotspotMBean =
ManagementFactory.newPlatformMXBeanProxy(server,
"com.sun.management:type=HotSpotDiagnostic",
HotSpotDiagnosticMXBean.class);
hotspotMBean.dumpHeap(fileName, live);
logger.fine("Heap dump done");
return true;
} catch (Throwable e) {
logger.log(Level.WARNING, "Error: " + e, e);
}
return false;
}
示例11: getHotspotMBean
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
private static HotSpotDiagnosticMXBean getHotspotMBean() {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<HotSpotDiagnosticMXBean>() {
public HotSpotDiagnosticMXBean run() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> s = server.queryNames(new ObjectName(HOTSPOT_BEAN_NAME), null);
Iterator<ObjectName> itr = s.iterator();
if (itr.hasNext()) {
ObjectName name = itr.next();
HotSpotDiagnosticMXBean bean =
ManagementFactory.newPlatformMXBeanProxy(server,
name.toString(), HotSpotDiagnosticMXBean.class);
return bean;
} else {
return null;
}
}
});
} catch (Exception exp) {
throw new UnsupportedOperationException(exp);
}
}
示例12: getHotSpotDiagnosticMXBean
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
hotspotDiagnosticMXBean =
newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
}
return hotspotDiagnosticMXBean;
}
示例13: getVMOption
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
/**
* Returns value of VM option.
*
* @param name option's name
* @return value of option or {@code null}, if option doesn't exist
* @throws NullPointerException if name is null
*/
protected static String getVMOption(String name) {
Objects.requireNonNull(name);
HotSpotDiagnosticMXBean diagnostic
= ManagementFactoryHelper.getDiagnosticMXBean();
VMOption tmp;
try {
tmp = diagnostic.getVMOption(name);
} catch (IllegalArgumentException e) {
tmp = null;
}
return (tmp == null ? null : tmp.getValue());
}
示例14: main
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list =
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
HotSpotDiagnosticMXBean mbean = list.get(0);
checkDiagnosticOptions(mbean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
checkDiagnosticOptions(mbean);
}
示例15: main
import com.sun.management.HotSpotDiagnosticMXBean; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
List<HotSpotDiagnosticMXBean> list =
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
HotSpotDiagnosticMXBean mbean = list.get(0);
checkVMOption(mbean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
HotSpotDiagnosticMXBean.class);
checkVMOption(mbean);
}