私はよく知っています
http://download.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html
スレッドが取得した CPU 時間をテスト\プロファイル\測定したいと思います。スレッド コンストラクターに以下を追加しました。
ManagementFactory.getThreadMXBean().setThreadCpuTimeEnabled(true);
if(!ManagementFactory.getThreadMXBean().isCurrentThreadCpuTimeSupported())
System.err.println("measure is not supported.");
ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true);
if(!ManagementFactory.getThreadMXBean().isCurrentThreadCpuTimeSupported())
System.err.println("contention is not supported.");
次に、スレッドの実行が終了したら、次を実行しました。
long tID = Thread.currentThread().getId();
long execTime = ManagementFactory.getThreadMXBean().getThreadCpuTime(tID);
しかし、私のスレッドのほとんどは、CPU を占有していることを絶対に確信しており、実行時間はゼロ (execTime == 0) です。
スレッドの測定方法を教えてください。上記の手順で何が問題になる可能性がありますか?
ありがとうございます。