csilk
csilk

Reputation: 188

Debugging a slow Java method

VisualVM is showing me that a particular method is taking a long time to execute.

Are there any widely used strategies for looking at the performance (in regards to time) of a Java method?

My gut feeling is that the sluggish response time will come from a method that is somewhere down the call hierarchy from the one VisualVM is reporting but I think getting some hard numbers is better than fishing around in the code based on an assumption when it comes to performance.

Upvotes: 1

Views: 302

Answers (2)

Ravi K
Ravi K

Reputation: 1016

You need to use tools like JProfiler, Yourkit etc. You can profile you code in depth & you can exactly catch which method is taking much time. You can go as much in depth hierarchy as you want with these tools.

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533530

VisualVM should be showing you the methods which use the most CPU. If the biggest user is your method, it means it not a method you are calling unless you are calling many methods which individually look small but in total are more.

I suggest you take the difference of the methods this method calls and your total. That is how much your method is adding which being profiled. Note: how much it adds when not profiled could be less as the profiler has an overhead.

Upvotes: 2

Related Questions