Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Set up JDK Mission Control with Red Hat Build of OpenJDK

March 15, 2019
Syed M Shaaf
Related topics:
JavaLinux
Related products:
Red Hat Enterprise Linux

Share:

    JDK Mission Control is now the newest member of the Red Hat Software Collections (RHSCL). JDK Mission Control is a powerful profiler for HotSpot Java virtual machines (JVMs) and has an advanced set of tools that enable efficient and detailed analysis of the extensive data collected by JDK Flight Recorder. The toolchain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments using OpenJDK 11.

    In this article, I will go through a primary example of setting up JDK Mission Control. For Linux, JDK Mission Control is part of the RHSCL and, for Windows, it is available as part of the OpenJDK zip distribution on the Red Hat Customer Portal.  For Linux, these instructions assume that Red Hat Build of OpenJDK 11 is already installed. I will show how to set up the system to install software from RHSCL, which provides the latest development technologies for Red Hat Enterprise Linux. Then, I will install the JDK Mission Control and run a simple sample application. The whole tutorial should take fewer than 10 minutes to complete.

    Installing Mission Control

    For Microsoft Windows

    For Microsoft Windows, the OpenJDK zip available via the Red Hat Customer Portal now contains JDK Mission Control and JDK Flight Recorder. Once un-archived, the JMC binary can be found in the bin directory.

    For Red Hat Enterprise Linux

    You can add or remove software repositories from the command line using the subscription-manager tool as the root user. Use the --list option to view the available software repositories and verify that you have access to RHSCL:

    $ su -
    # subscription-manager repos --list | egrep rhscl

    Depending which variant is used (e.g., server or workstation), you can enable the repo with the following command:

    # subscription-manager repos --enable  rhel-variant-rhscl-7-rpms

    Install JMC with the following command:

    $ yum install rh-jmc

    We have now installed JMC. You can launch it by typing JMC or heading off to the applications menu.

    If you are running multiple versions of Java, as I do, and want to launch JMC from the command line, use the following options to launch JMC with the path to the Red Hat Build of OpenJDK.

    $ scl enable rh-jmc bash
    $ jmc -vm /usr/lib/jvm/java-11-openjdk-11.0.2.7-0.el7_6.i386/bin

    Real-time Monitoring

    JMC allows you to perform real-time monitoring of JVMs. To do this, create a new connection from the File Menu, choose your JVM, and start JMX console. The result should give you an overview page with Processors, Memory consumption, Java heap use, JVM CPU usage, etc.

    Now that we have JMC set up, let's try to run an example and see how it works.

    The following is a simple example of reading a couple of files. Indeed, there can be issues that we have not taken into consideration. In the example below, I have two files: a simple HTML file and a text file, which is about 1 GB.

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    
    
    public class TextFileReader {
    
    private File textFilePath = null;
    
    
    public TextFileReader(String textFilePath) {
        if (textFilePath == null)
            throw new IllegalArgumentException();
        this.textFilePath = new File(textFilePath);
    }
    
    public void readFile() throws IOException {
        FileReader fileReader = new FileReader(textFilePath);
        BufferedReader bufferedreader = new BufferedReader(fileReader);
        StringBuffer sb = new StringBuffer();
        String strLine;
        while ((strLine = bufferedreader.readLine()) != null) {
            sb.append(strLine);
            sb.append("\n");
        }
        
        fileReader.close();
        System.out.println(sb.toString());
    }
    
    public static void main(String[] args) throws IOException{
    
        new TextFileReader("index.html").readFile();
        new TextFileReader("test.txt").readFile();
    
    }
    
    }

    Let’s execute the following commands to compile and run this example.

    $ javac TextFileReader.java
    
    $ java -XX:+FlightRecorder -XX:StartFlightRecording=dumponexit=true,filename=filereader.jfr TextFileReader

    In the above Java command, the parameter -XX:StartFlightRecording will dump the results into filereader.jfr.

    Let's look at the results by opening this file in JMC.

    JMC reports in-depth details on the entire run; for example, JVM internals shows that GC is Stalling. Moreover, with a large file with not much memory, that is a problem, so we can fix the issue either by lowering the value of -XX:InitiatingHeapOccupancyPercent and even more so ensuring that there is enough memory (e.g., Xms1024m -Xmx4096m).

    Another great example can be found here by Jie Kang, Software Engineer at Red Hat, where he shows how the method profiling works, aiding in optimization of the original code.

    JMC is very useful for understanding application behavior such as memory leaks, deadlock, and much more. Give it a try with the Red Hat Build of OpenJDK 11

    Last updated: November 1, 2023

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue