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.
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 18.104.22.168, 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
These are the options to add to the Tomcat startup file (you may need to create the file):
These should be set in a file called
setenv.sh, in the
binfolder, 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 =
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.hproffile from the Tomcat folder to your own local computer.
This may require copying or moving the file and changing its ownership or permissions.