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);
}
}
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
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