Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers| Heap dump analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Training online: Concurrency, Threading, GC, Advanced Java and more ... 

Tool Report: NetBeans Profiler

Get rid of your performance problems and memory leaks!

Modern Garbage Collection Tuning
Shows tuning flow chart for GC tuning

Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:

Training online
Threading Essentials course

Get rid of your performance problems and memory leaks!

Published January 2007 (Initially Published November 2005)

The Tool Reports are designed to help readers make informed choices about the tools they may wish to use. provides these reports as a service to our readers; is not responsible for the information provided by the tool author or vendor, nor do we necessarily endorse the products mentioned. is not responsible for any additional resources provided from the article (such as downloadable files or other accessible material), even where we host such material.


The NetBeansTM Profiler is an optional feature of the NetBeans Integrated Development Environment (IDE). The NetBeans Profiler is a powerful tool that provides important information about the runtime behavior of an application. Imposing relatively little overhead, the NetBeans Profiler tracks thread state, CPU performance, and memory usage. It uses innovative technology to allow you to tightly control exactly which parts of an application are profiled, resulting in reduced overhead and easier to interpret results. The profiled application can run locally or on a remote system. And by being tightly integrated into the IDE workflow the NetBeans Profiler makes it easy to identify performance problems and memory leaks.

Supported Java VMs

The NetBeans Profiler can profile applications running on the following JVMs:

Installing the NetBeans Profiler

  1. Download the profiler pack installer for your platform from the NetBeans Profiler homepage.
  2. If you have a previous version of the NetBeans Profiler installed, uninstall it first - see the instructions on the download page.
  3. Launch the downloaded installer.
  4. Proceed through the steps of the installer wizard to install the module.
  5. (Re)Start the NetBeans IDE.

Once installed, the module adds the Profile menu item to the menu bar. The Profile menu allows you to start profiling and work with the results. The module also adds two toolbar buttons that are shortcuts to the Profile command ( profile button ) and the Attach and Profile command ( attach and profile button ).

Related Products

The NetBeans IDE is the base product on which Sun Java Studio Enterprise (JSE) is built. JSE also offers profiling features.

Getting Started

The NetBeans Profiler provides a number of internal settings that let you tune profiling to your needs. For example, you may decrease the profiling overhead at the cost of some reduction in the amount of generated information. However, it may take some time to understand the meaning and use of the numerous settings available in the NetBeans Profiler.

For most applications, certain default settings are sufficient. For this reason, the NetBeans Profiler offers two major profiling options. You can start profiling by choosing a simple predefined profiling task, which has most of the settings preset to optimal values and therefore requires little or no tuning. Alternatively, you can create your own custom profiling configuration, where you are free to modify any of the available settings.

To start profiling an application:

  1. Open your project in the NetBeans IDE.
  2. Right-click your project's entry in the Projects window and then select Set Main Project.
  3. Choose Profile > Profile Main Project from the main menu.
  4. Choose a profiling command from the list in the Select Profiling Task dialog box.
  5. Click Run.

When you click Run, the target application launches and the selected profiling command starts. The NetBeans Profiler control panel opens in the IDE.

To see the results of the profiling command, click the Live Results button ( Live Results ) in the Profiler control panel to open the Profiling Results tab.

To stop the profiling command, choose Profile > Stop from the Profile menu or click the Stop button ( Stop ). If you start the application with the NetBeans Profiler, when you stop the profiling command the application also stops.

Profiling Tasks

The Select Profiling Task dialog box is the main interface for selecting and running profiles. The dialog box gives you five different ways of profiling the target application. The first four are predefined profiling commands. The last command, Run Custom Profiling, allows you to create your own custom profiling configuration.

profiling panel

When you click on a profiling command the box expands, displaying a brief explanation of the command and, for some tasks, allowing you to set some profiling options. Clicking Run at the bottom of the dialog box launches the target application and starts the selected profiling command.

Only one task, i.e. one kind of profiling, can be active for the profiled application at any given time (monitoring is always active however, even when another task is chosen, since its overhead is very low). Note that while profiling you can switch between profiling tasks without stopping and restarting your application.

You can choose from the following profiling tasks:

  1. Monitor Application

    This profile command displays high-level information about several important properties of the target JVM, including thread activity and memory usage.

  2. Analyze Performance

    Application Performance profiles method-level CPU performance (execution time). You can choose to profile the entire application or a part of the application. Detailed filters can be set to control exactly which methods get profiled, allowing the rest of your application to run at full speed.

  3. Analyze Code Fragment Performance

    This command measures the time it takes to execute an arbitrary piece of code within one method, or the whole method. By analyzing a code fragment rather than the entire application, the profiling overhead is greatly reduced. The absolute results that you obtain in this mode are closest to the real runtime performance, since the instrumentation is the most lightweight.

  4. Analyze Memory Usage

    When you analyze memory usage, the profiling results displayed depend on which of the following options you choose:

    By default only ten percent of all objects for each class are tracked by the NetBeans Profiler. This statistical approach has been shown to deliver results that are as accurate as when all objects are tracked, but with the benefit of greatly reduced profiling overhead.

  5. Run Custom Profiling

    This command is for running custom profiling configurations. You can create, edit, and save these custom configurations, allowing you to control all the internal profile settings.

Control Panel

The profiling control panel is displayed in the left pane of the IDE when you run the NetBeans Profiler. You can open the control panel by choosing Window > Profiling > Profiler Control Panel. It contains controls that do the following:

control panel


The NetBeans Profiler provides several displays of information.

The VM Telemetry Overview is always displayed when the Monitor Application command is chosen. To display it at any other time, select Profile > View > Telemetry Overview.

VM telemetry overview

In the graph on the left the red shading indicates the allocated size of the JVM heap. The purple overlay indicates the amount of heap space actually in use. In the example above the allocated heap size at the last update was over 300 megabytes. Of that about 20 megabytes is actually being used to hold Java objects.

The graph on the right shows the count of active threads in the JVM.

The graph in the center shows two important heap statistics.

Thread State

Thread state is optionally displayed when the Monitor Application command is chosen. It contains the following tabs:

A sample timeline graph is shown below.

graph of threads

Color coding is used to display thread state:

Live Results

Clicking the Live Results button ( Live Results ) in the control panel will open the Profiling Results tab. Depending on the profiling command that is running, this tab will display either performance or object allocation and liveness statistics.

The NetBeans Profiler will update the displayed profiling results automatically at short intervals (about 2 seconds) if the Update Results Automatically button ( Auto-refresh button ) in the toolbar is clicked.

CPU Snapshot

The CPU Snapshot captures data on method call chains, times, and invocations when profiling CPU performance, either from the Analyze Performance predefined task or when running a custom CPU profile. The CPU Snapshot is displayed when you click the Take Snapshot button ( take snapshot button ) in the control panel.

The CPU snapshot contains the following tabs:

Reverse Call Graph

Memory Snapshot

The Memory Snapshot captures data on object allocation and liveness when profiling memory usage with the Analyze Memory Usage command or when doing memory profiling in a custom profile. The Memory Snapshot is displayed when you click you click the Take Snapshot button ( take snapshot button ) in the control panel.

The Memory snapshot contains the following tabs:

memory snapshot


This example demonstrates just one feature of the NetBeans Profiler: the ability to quickly identify CPU performance problems. The example is a web application that just calculates prime numbers. When attempting to find performance bottlenecks, you typically know which features are running slowly. That allows you to narrow down the search for the bottleneck to a top level method for that feature. The NetBeans Profiler supports this by allowing you specify a root method for profiling.

  1. A profiling session begins by selecting a project as the IDE's Main Project. Then Profile > Profile Main Project is chosen from the IDE menu.
  2. The Select Profiling Task dialog is displayed.
  3. The Analyze Performance button is clicked.
  4. The Part of Application radio button is clicked. Then the Select button is used to select the class that contains the root method. In this case the class is demo.Performance and the method is processRequest. This means that the demo.Performance.processRequest method and all methods that it calls, and all methods that they in turn call (and so on) will be profiled. Starting from demo.Performance.processRequest, the Profiler does analysis of the method call graph to determine which methods need profiling. Only those methods are profiled - the rest of the application will continue to run at full speed with no profiling overhead.

    Select root method

  5. Particularly when profiling web or enterprise applications, there are usually large blocks of code that you do not want to profile. In this example, the web server is Tomcat and there is no need to do profiling of Tomcat's code. So in the Analyze Performance window, the Quick Filter is used to specify methods that should not be profiled. The string org.apache is specified so that all methods in the org.apache package (and child packages) will not be profiled - even if they are called from the root method that was selected. This reduces profiling overhead and filters out information that is not relevant.

    Set Quick Filter Dialog

  6. Clicking the Run button in the Select Profiling Task window starts the profiling session. The IDE will start Tomcat and display the web application's index.jsp page in a web browser window. At the same time, the Profiler will run in the background.
  7. The portion of the web application that causes the root method to run is then invoked by interacting with the application's user interface.
  8. After the application responds, the Profile > Take Snapshot of Collected Results command is selected in the IDE. The Profiler displays the performance results, as illustrated below.

    View Performance Results.

    The top window shows the complete method call graph beginning with the root method. The bottom window is a flatter depiction; it shows the Hot Spots in the application - those methods that took the most time to execute.

  9. To examine and interpret the results, notice that the processRequest method ran for a total of 4308 milliseconds (ms). Note, however, that very little time was spent running the instructions of the processRequest method itself - the "self time" for processRequest is only 10.1 ms. The vast majority of the time was spent in methods called by processRequest. The Hot Spots displayed in the bottom window are sorted by "self time." By looking at that list you can see that the calculate method took up 97.8% of the execution time. This is not surprising given the amount of work the calculate method has been given to do and the inefficient way it goes about doing that work.
  10. To help you decide how your application can be optimized, the NetBeans Profiler helps you identify bottlenecks in your code that were not expected or that will prevent your application from scaling well. From here, it is possible to right-click the calculate entry and choose Go To Source in order to examine the source code. As a comparision to calculate's runtime, the Profiler output of an optimized algorithm in a method called calculate2, is shown below. Notice that the processRequest method ran for only 107ms and the calculate2 method took up less than 10% of the execution time!

    View Performance Results.

Upcoming Features

The 5.5 release of the NetBeans Profiler did not add much to the set of profiling features described in this tool report. It did add support for easily starting profiling sessions on enterprise applications and Enterprise Java Bean (EJB) code. It also added support for several environments that were not supported before. These include support for: 64-bit JVMs, application servers such as GlassFish and JBoss, and support for the Apple Mac OS X operating system. For full details, refer to What's New In NetBeans Profiler 5.5.

Looking ahead to NetBeans Profiler 6.0, the Profiler development team is planning to add several new features that help make the NetBeans Profiler even easier to use and more comprehensive. These features include:

All of the features listed above are still under development. Milestone builds of version 6.0 of the NetBeans IDE and the NetBeans Profiler are being made available on a regular basis - more information on milestones is available here. So please try out these new features - the NetBeans Profiler development team is interested in hearing your feedback:


The NetBeans Profiler is a powerful tool that provides important information about the runtime behavior of an application. It can be used to identify thread state problems, CPU performance bottlenecks, and memory usage bugs. For more information, please visit the NetBeans Profiler homepage.

Last Updated: 2023-09-28
Copyright © 2000-2023 All Rights Reserved.
All trademarks and registered trademarks appearing on are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed:
Trouble with this page? Please contact us