Book Image

Java EE 6 Development with NetBeans 7

By : David R Heffelfinger
Book Image

Java EE 6 Development with NetBeans 7

By: David R Heffelfinger

Overview of this book

<p>NetBeans has several features that greatly simplify Java EE development, but with many features and great flexibility, Java developers can become overwhelmed by the options available in NetBeans. This book provides step-by-step recipes that show you how to take control of the environment and make use of these features to make your enterprise Java application development more efficient and productive than ever before, so that you can concentrate on the important parts of your application.<br /><br /><em>Java EE 6 Development with NetBeans 7</em> takes you through the most important parts of Java EE programming and shows you how to use the features of NetBeans that will improve your development experience with clear, careful instructions and screenshots. It will show you how to use NetBeans functionality to automate many of the tedious or repetitive tasks frequently encountered when developing enterprise Java applications, freeing you up to focus on the business logic specific parts of the application. As well as showing you time-saving tricks, keyboard shortcuts, and other productivity enhancements possible with NetBeans, it will take you through the major Java EE APIs and how to get them working in the NetBeans environment.</p> <p>While focusing on NetBeans features, you will learn about developing applications using the servlet API and JSPs, including taking advantage of JSTL and developing custom JSP tags. Developing applications that take advantage of JavaServer Faces is also covered in detail, including how to generate standard JSF applications from an existing database schema. The book also covers how to easily develop elegant JSF applications by taking advantage of the PrimeFaces JSF 2.0 component library that is bundled with NetBeans.</p>
Table of Contents (20 chapters)
Java EE 6 Development with NetBeans 7
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Identifying Performance Issues with the NetBeans Profiler
Index

Profiling our application


All we need to do in order to profile our application is right-click on it in the Projects window and select Profile. At that point, the following window will pop up:

As we can see, there are several aspects of our application we can profile, such as memory allocation and CPU usage. One of the most useful features of the NetBeans profiler is the ability to report how long each method invocation in our application is taking, this information is provided when we profile CPU usage.

In order to start profiling, we simply click on the Run button. At this point the application server will be started in profiling mode, and our application will be deployed and executed. After a few seconds the Profiler control panel will open.

At this point we can see how long each method is taking and how many times each method has been executed by simply clicking on the Live Results button.

The Live Profiling Results window displays every method invocation, along with the percentage of total time in the application that the method is using, and the number of milliseconds the method takes to complete, it also shows how many times each method has been invoked.

As we can see, the NetBeans profiler can be very helpful in pinpointing areas of our application that are having performance problems, allowing us to easily identify these areas so that we can better focus our performance optimization efforts.

Although this information is very valuable, it is by no means the only information we can obtain from the NetBeans profiler. We can see how much memory our application is using by simply opening the VM Telemetry Overview window by clicking on the VM Telemetry icon on the Profiling control panel.

After clicking the VM Telemetry Icon, the VM Telemetry window opens. This window has three tabs:

The graph on the left tab shows (in red) the total amount of heap allocated in our application's Java Virtual Machine. Additionally, it also shows the total amount of heap used by our application.

The graph in the middle tab is useful for detecting "memory leaks" (Java has garbage collection, therefore in theory memory leaks are impossible. However, if we keep references to objects that are no longer needed they are never garbage collected, therefore a memory leak is possible). The purple line in the middle graph indicates the amount of time the JVM spends doing garbage collection. The red line indicates Surviving Generations . A generation is a set of objects that were created within two garbage collection intervals. A surviving generation is a generation that survived one or more garbage collections. We can force our application to garbage collect by clicking on the icon in the Profiling control panel:

If the graph indicates a high number of surviving generations between garbage collections, then we might have a memory leak in our application.

The graph on the right tab of the VM Telemetry Overview window indicates the number of active threads and the number of loaded classes in our application.