Java 5でjmxを使用してプログラムでヒープ情報を取得する
質問
jconsoleを使用してJavaプロセスにアタッチし、メモリ情報を取得することを認識しています。具体的には、さまざまなメモリプールに関する情報をプログラムで取得した後、監視アプリケーションに関連付けることができます。
ありがとう!
解決
mattkに感謝-基本的にこれをやった:-)
List memBeans = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator i = memBeans.iterator(); i.hasNext(); ) {
MemoryPoolMXBean mpool = (MemoryPoolMXBean)i.next();
MemoryUsage usage = mpool.getUsage();
String name = mpool.getName();
float init = usage.getInit()/1000;
float used = usage.getUsed()/1000;
float committed = usage.getCommitted()/1000;
float max = usage.getMax()/1000;
float pctUsed = (used / max)*100;
float pctCommitted = (committed / max)*100;
}
他のヒント
所属していません StackOverflow