Create Java Heap Dumps for Tomcat

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Welcome to this hands-on lab, where we will obtain a heap dump of a running Tomcat instance, and also enable the start-up option to create a heap dump on an _Out of memory_ error.

We are using Apache’s Tomcat, a Java-based application platform built around deploying and managing Java Web Applications. The server provided in this lab environment is running Red Hat Enterprise 8 and has Tomcat 9 pre-installed for you, available on port **8080**.

You will log into the server and perform the associated tasks.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Test to Ensure You Can Access the Preconfigured Tomcat Instances on Port 8080

Visit the Tomcat server’s public IP address on port 8080. Connect to the Tomcat GUI and log in. The username and password to use are the same as what’s provided for CLI access.

To access the server, copy the external IP address and test in your browser by using this IP address and appending the :8080 to it.

For example, if the server’s IP address is, then you would put the following into your web browser:

You should see the Tomcat GUI.

Note: It may take from 3 to 10 mins after the hands-on lab has started before you can access the Tomcat server.

Set the Option for a Heap Dump on Out of Memory Error

You will need to set a startup option for Tomcat so that it creates a heap dump on an Out of memory error.

The file that is automatically created should go to /usr/local/tomcat9, and should be called heapcheck.hprof.

These are the options to add to the Tomcat startup file (you may need to create the file):

  1. -XX:+HeapDumpOnOutOfMemoryError

These should be set in a file called, in the bin folder, and they should be exported as CATALINA_OPTS.

Create a Manual Heap Dump and Call It heapcheck.hprof

Use the appropriate command to create a heap dump from live memory, and call it

Use the following options for the heap dump:

  • Only live objects
  • Binary format
  • File = heapcheck.hprof

You will need to be in the correct folder to be able to perform this successfully.

If you get an error, you are not in the correct location to perform the task.

Transfer the heapcheck.hprof File from the Tomcat Server to Your Local Computer

You will need to do the tasks required to get the /usr/local/tomcat9/heapcheck.hprof file from the Tomcat folder to your own local computer.

This may require copying or moving the file and changing its ownership or permissions.

Additional Resources

You have been tasked with enabling the option to automatically have a heap dump created when there's an Out of memory error.

These heap dump files should be placed in the /usr/local/tomcat9 folder, where they'll be picked up by someone else in your organization at a later date. They should be called heapcheck.hprof.

You will need to create a bin/ file for this task. You should be able to see that the heap dump option is enabled when you do a ps -ef | grep java command from the command line.

Note: It may take 3 to 10 minutes after the hands-on lab has started before you are able to log into the server. This is fine and will not affect the performance of the tasks for the hands-on lab.

Logging In

Use the credentials provided on the hands-on lab page, and log in to the provided server as cloud_user. Note that this is for connecting to the server and also to the Tomcat GUI.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?