java如何测量方法调用时间? [英] java how can I measure method call times?

查看:135
本文介绍了java如何测量方法调用时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的类,我想测量方法调用时间,我该怎么做?寻找通用的方法来实现这一目标,因此我也可以将其应用于更困难的类。谢谢

I have a simple class and I would like to measure method call times how can I do that? Looking for generic way to achieve that so I can apply it to more difficult classes as well. Thank you

import java.io.*;
import java.util.*; 

public class Turtle {
  private String name;
  private Formatter f;
  public Turtle(String name, Formatter f) {
    this.name = name;
    this.f = f;
  }

  public void move(int x, int y) {
    f.format("%s The Turtle is at (%d,%d)\n", name, x, y);
  }

  public static void main(String[] args) {
    PrintStream outAlias = System.err;
    Turtle tommy = new Turtle("Tommy",
      new Formatter(System.out));
    Turtle terry = new Turtle("Terry",
      new Formatter(outAlias));
    tommy.move(0,0);
    terry.move(4,8);
    tommy.move(3,4);
    terry.move(2,5);
    tommy.move(3,3);
    terry.move(3,3);
  }
}


推荐答案

使用专用工具将向您显示更多您需要的工具:)我认为VisualVM是最好的工具,但是还有其他可用工具(例如JDK本身提供的JConsole或付费的JRockit)。

了解更多信息在我的文章中

Use dedicated tools that will show You even more You need :) VisualVM is best one in my opinion, However there are other available (e.g. JConsole that is provided in JDK natively, or JRockit that is paid).
Read more here on my post

这些工具显示正在运行的应用程序和它们消耗的资源以及Servlet(如果有)的处理时间,错误和调用计数等。还实例化了线程和类被列为。这肯定会满足您的需求

These tools shows running apps and resources consumed by them along with servlets (if any) processing times, error and call counts etc. Also threads and classes instantiated are listed. This will surely satisfy Your needs

这篇关于java如何测量方法调用时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆