July 29, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Java Profiling with WSAD 5.0

  • April 11, 2006
  • By Aleksey Shevchenko
  • Send Email »
  • More Articles »

After profiling your modified code, you can observe that the number of "Live Instances" of the DummyClass is 0 and the number of "Collected" instances equals to the number "Total" instances of the DummyClass. (See Figure 8.)



Click here for a larger image.

Figure 8

In this example, you have observed that the use of this profiling tool helps you identify and correct memory leaks.

Hands-on Example: Identifying Method Response Times

In the second example, you will identify method response times using the WSAD Profiling Tool. In the class below, you are calling a number of methods that each sleep for a predefined number of seconds. In this example, you will repeat Steps 1–7 from the previous section. (The link to the full source code of this class, ProfileTestTwo.java, is located in the zip file at the end of this article.)

1. package com.profile.examples;
2.
3. public class ProfileTestTwo {
4.
5.    public void methodOne() throws InterruptedException {
6.       Thread.sleep(1000);
7.    }
8.
9.    public void methodTwo() throws InterruptedException {
10.       Thread.sleep(2000);
11.    }
12.
13.    public void methodThree() throws InterruptedException {
14.       Thread.sleep(3000);
15.    }
16.
17.
18.    public static void main(String[] args)
          throws InterruptedException{
19.       ProfileTestTwo testTwo = new ProfileTestTwo();
20.       for (int i = 0; i < 10 ; i++) {
21.          testTwo.methodOne();
22.          testTwo.methodTwo();
23.          testTwo.methodThree();
24.       }
25.    }
26. }

This time, you are interested in a different Profiling Perspective to observe the results. After the profiling session finishes its execution, right-click on the default monitor --> Open With --> Method Statistics.



Click here for a larger image.

Figure 9

You can observe that the methodThree() method takes the longest cumulative time because it spends the longest amount of time in sleeping mode.

Conclusion

In this article, you have learned how to use the WSAD Profiling Tool to identify memory leaks and method invocation times. The tool benefits developers because it is a means to identify issues that are not evident on the surface.

Download the Code

You can download the code that accompanies this article here.

About the Author

Aleksey Shevchenko has been working with object-oriented languages for over seven years. He has been implementing Enterprise IT solutions for Wall Street and the manufacturing and publishing industries.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel