简体   繁体   中英

ManagementFactory issue while upgrading eclipse project to jdk1.7

I am trying to upgrade an eclipse project from jdk 1.6 to jdk 1.7 .

The following error shows up during compilation for

import sun.management.ManagementFactory;

The type sun.management.ManagementFactory is not visible.

I tried importing java.lang.management.ManagementFactory to resolve the error; but then the following line of code is throwing an error.

ManagementFactory.getDiagnosticMXBean().dumpHeap

Error : The method getDiagnosticMXBean() is undefined for the type ManagementFactory .

Can someone please help understand what is causing this issue and how to resolve it?

In Java 7 (using officially released java.lang.management.ManagementFactory ) you may want to try the combination of getMemoryMXBean() with getHeapMemoryUsage() as following:

ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

Please note: the above has not been tested.

EDIT:

System.out.println(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().toString());

actually works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM