ブログ

ej-technologies の製品ニュース、アップデート、および技術に関する知見。

RSS で読む。 メール で購読。 でフォロー。

Methods statistics and exceptional method runs

2011-02-12
投稿者: Ingo Kegel

In the screencast below, I explain how to analyze exceptionally slow invocations of frequently invoked methods. By using the method statistics and exceptional method run features in JProfiler, the slowest invocations are shown separately in the call tree.

The test class that is profiled in this screen cast is given below:

import java.util.Random;
  
public class MethodStatisticsTest {

    private static Random random = new Random(0);

    public static void main(String[] args) {
        while (true) {
            doCriticalTask();
        }
    }

    private static void doCriticalTask() {
        if (random.nextInt(1000) % 999 == 0) {
            implOne();
        } else {
            implTwo();
        }
    }

    private static void implOne() {
        for (int i = 0; i < 100000; i++) {
            Math.sqrt(i);
        }
    }

    private static void implTwo() {
        for (int i = 0; i < 1000; i++) {
            Math.sqrt(i);
        }
    }
}
アーカイブ