0

私はよく知っています

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) です。

スレッドの測定方法を教えてください。上記の手順で何が問題になる可能性がありますか?

ありがとうございます。

4

1 に答える 1

0

Thread Topを見てください。すべて完了しているため、車輪を再発明する必要はありません。

于 2011-06-23T10:08:11.900 に答える