Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:


Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

November Discount Launch 2022 – TEMP TOP (NPI)
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:


1. Overview

Sometimes writing code that just runs is not enough. We might want to know what goes on internally such as how memory is allocated, consequences of using one coding approach over another, implications of concurrent executions, areas to improve performance, etc. We can use profilers for this.

A Java Profiler is a tool that monitors Java bytecode constructs and operations at the JVM level. These code constructs and operations include object creation, iterative executions (including recursive calls), method executions, thread executions, and garbage collections.

In this article, we'll be discussing the main Java Profilers: JProfiler, YourKit, Java VisualVM, the Netbeans Profiler, and the IntelliJ Profiler.

2. JProfiler

JProfiler is a top choice for many developers. With an intuitive UI, JProfiler provides interfaces for viewing system performance, memory usage, potential memory leaks, and thread profiling.

With this information, we can easily know what we need to optimize, eliminate, or change – in the underlying system.

This product requires purchasing a license, but also offers a free trial.

Here's what the JProfiler's interface looks like:

jprofiler overview probingJProfiler overview interface with features

Like most profilers, we can use this tool for both local and remote applications. This means that it's possible to profile Java applications running on remote machines without having to install anything on them.

JProfiler also provides advanced profiling for both SQL and NoSQL databases. It provides specific support for profiling JDBC, JPA/Hibernate, MongoDB, Casandra, and HBase databases.

The below screenshot shows the JDBC probing interface with a list of current connections:

jprofiler database probing 1JProfiler database probing view

If we are keen on learning about the call tree of interactions with our database and seeing connections that may be leaked, JProfiler nicely handles this.

Live Memory is one feature of JProfiler that allows us to see current memory usage by our application. We can view memory usage for object declarations and instances or for the full call tree.

In the case of the allocation call tree, we can choose to view the call tree of live objects, garbage-collected objects, or both. We can also decide if this allocation tree should be for a particular class or package or all classes.

The screen below shows the live memory usage by all objects with instance counts:

jprofiler live memoryJProfiler live memory view

JProfiler supports integration with popular IDEs such as Eclipse, NetBeans, and IntelliJ. It's even possible to navigate from snapshot to source code!

3. YourKit

YourKit Java Profiler runs on many different platforms and provides separate installations for each supported operating system (Windows, MacOS, Linux, Solaris, FreeBSD, etc.).

Like JProfiler, YourKit has core features for visualizing threads, garbage collections, memory usage, and memory leaks, with support for local and remote profiling via ssh tunneling.

YourKit offers both paid licenses for commercial use, with a  free trial, and lower cost or free licenses for non-commercial use.

Here's a quick look at the memory profiling results of a Tomcat server application:

yourkit tomcat profiling memoryYourKit Java Profiler memory profiling of Tomcat server application

YourKit also comes in handy those times when we want to profile thrown exceptions. We can easily find out what types of exceptions were thrown and the number of times each exception occurred.

YourKit has an interesting CPU profiling feature that allows focused profiling on certain areas of our code such as methods or subtrees in threads. This is very powerful as it allows for conditional profiling through its what-if feature.

Figure 5 shows an example of the thread-profiling interface:

yourkit threads profilingFigure 5. YourKit Java Profiler threads profiling interface

We can also profile SQL, and NoSQL database calls with YourKit. It even provides a view for actual queries that were executed.

Though this is not a technical consideration, the permissive licensing model of YourKit makes it a good choice for multi-user or distributed teams, as well as for single-license purchases.

4. Java VisualVM

Java VisualVM is a simplified yet robust profiling tool for Java applications. This is a free, open-source profiler.

This tool was bundled with the Java Development Kit (JDK) up to JDK 8, but was removed in JDK 9 and is now distributed as a standalone tool: VisualVM Download.

Its operation relies on other standalone tools provided in the JDK, such as JConsole, jstat, jstack, jinfo, and jmap.

Below, we can see a simple overview interface of an ongoing profiling session using Java VisualVM:

visualvm overviewJava VisualVM local tomcat server app profiling

One interesting advantage of Java VisualVM is that we can extend it to develop new functionalities as plugins. We can then add these plugins to Java VisualVM's built-in update center.

Java VisualVM supports local and remote profiling, as well as memory and CPU profiling. Connecting to remote applications requires providing credentials (hostname/IP and password as necessary) but does not provide support for ssh tunneling. We can also choose to either enable real-time profiling with instant updates (typically every 2 seconds).

Below, we can see the memory outlook of a Java application profiled using Java VisualVM:

visualvm sample memoryJava VisualVM memory heap histogram


With the snapshot feature of Java VisualVM, we can take snapshots of profiling sessions for later analysis.

5. NetBeans Profiler

The NetBeans Profiler is bundled with Oracle's open-source NetBeans IDE.

While this profiler shares a lot of similarities with Java VisualVM, it's a good choice when we want everything wrapped in one program (IDE + Profiler).

All other profilers discussed above provide plugins to enhance IDEs integration.

Below screenshot shows an example of the NetBeans Profiler interface:

netbeans telemetry viewNetbeans Profiler telemetry interface

Netbeans Profiler is also a good choice for lightweight development and profiling. NetBeans Profiler provides a single window for configuring and controlling the profiling session and displaying the results. It gives a unique feature of knowing how often garbage collection occurs.

6. IntelliJ Profiler

IntelliJ Profiler is a simple, yet powerful tool for CPU and memory allocations profiling. It combines the power of two popular Java profilers: JFR and Async profiler.

While there are some advanced features, the main focus is on ease of use. IntelliJ Profiler allows you to get started in a few clicks without any kind of configuration while providing helpful features to assist you in your day-to-day work as a developer.

As part of IntelliJ IDEA Ultimate, IntelliJ Profiler can be attached to a process with a single click and we can navigate between a snapshot and the source code as if they were one. Its other features, like differential flame graphs, allow us to visually assess the performance of different approaches and get insights into the runtime operations quickly and efficiently:

IntelliJ Profiler works on Windows, Linux, and macOS.

7. Other Solid Profilers

Some honorable mentions here are Java Mission Control, New Relic, and Prefix (from Stackify) – these have less market share overall, but definitely, do deserve a mention. For example, Stackify's Prefix is an excellent lightweight profiling tool, well-suited for profiling not only Java applications but other web applications as well.

8. Conclusion

In this write-up, we discussed profiling and Java Profilers. We looked at the features of each Profiler and what informs the potential choice of one over another.

There're many Java profilers available with some having unique characteristics. The choice of which Java profiler to use, as we've seen in this article, is mostly dependent on a developer's selection of tools, the level of analysis required, and the features of the profiler.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:


Generic footer banner
Comments are closed on this article!