Rakesh Juyal
Rakesh Juyal

Reputation: 36789

How to find out which method is taking much time?

One of my component is taking too much time to execute. It calls lots of services which in turn calls many dao methods. Now, is there any way to get the time taken by each method it is calling.
I don't want to write System.currentmillis before and after each method to calculate time taken as there are too many methods.
I think i may need to use interceptors or may be any profiler can do that. I am not sure, please help.

Upvotes: 18

Views: 16604

Answers (3)

posdef
posdef

Reputation: 6562

Use jvisualvm which should come with JDK (if I remember correctly). It's a GUI for your JVM, and has really nice functions. Check out its features there are some screenshots as well...

And you can follow these steps to integrate it as launcher in eclipse Steps to integrate in eclipse

Upvotes: 9

Mike Dunlavey
Mike Dunlavey

Reputation: 40689

Don't look at it as measuring time to find the problem.

Use its slowness to expose it. Just use the same method you would if it were an infinite loop.

That is, pause it a few times while it's being slow, and each time inspect the call stack of each thread. The guilty methods and lines of code will appear on multiple samples. Check the last paragraph of this post.

Here's more on how it works.

Upvotes: 1

Tom W
Tom W

Reputation: 578

You can use the Java Profiler in the NetBeans IDE.

Have a look here: http://netbeans.org/features/java/profiler.html

The Java VisualVM is another alternative: http://java.net/projects/visualvm/content/ . You can attach it to any running Java program, including ones you start through Eclipse.

Upvotes: 1

Related Questions