博客

来自 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);
        }
    }
}
归档