Best way to measure Memory Usage of a Java Program?

浪子不回头ぞ 提交于 2019-12-04 05:36:09
Runtime.getRuntime().freeMemory();

Runtime.getRuntime().totalMemory();

Look at the Runtime class. It has freeMemory, maxMemory, and totalMemory. That's probably close enough for your purposes.

You may prefer graceful method to measure memory, rather than hack image. JConsole is known to Monitor Applications by JMX,it provides program API. I guess it is what you need.

See: Using JConsole to Monitor Applications

Try JProfiler. Although its not free you can try evaluation version first.

The HPjmeter console is free. Run your Java process with -Xloggc:<file> and open the <file> with it. Not only can you save your sessions, but you can compare runs. Other options to consider including in your command line are:

-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!