DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Deployment of Spring MVC App on a Local Tomcat Server
  • Empowering Secure Access: Unleashing the Potential of Microsoft Entra ID Application Proxy
  • Testing Swing Application
  • Building A Simple AI Application in 2023 for Fun and Profit

Trending

  • KubeAdmiral: Next-Generation Multi-Cluster Orchestration Engine Based on Kubernetes
  • Implementing Data Lakes in Data Management
  • Understanding Zero Trust Security Building a Safer Digital World
  • Python “Magic” Methods (Part 2)

Profiling With JVisualVM

Learn more about profiling with the JVisualVM!

Vishal Saxena user avatar by
Vishal Saxena
·
Updated Feb. 07, 19 · Tutorial
Like (11)
Save
Tweet
Share
25.4K Views

Join the DZone community and get the full member experience.

Join For Free

A few days back, I faced an issue on one of the Java service-hosted servers. The server load, resource consumption, and response time of service were too high.

Everyone was under the impression that the latest deployment of the JAR caused this issue, whereas the service code and performance on the local machine looked fine.

To be sure, we need data for the latest deployment to not cause this issue — that's where the use case of JVisualVM comes.

What Is the JVisualVM?

This is one of the useful, free utilities that come in the JDK bundle. It's basically a JMX client application. This utility shows stats like memory used, heap data, garbage collector, and CPU profiling.

It helps us to improve the application performance after analyzing memory leaks, heap data, and CPU consumption

With features like thread analysis and head dump analysis, it is very handy in solving run-time problems, too.

Adding JMX Properties

To enable JVisualVM to collect stats of application hosted on a remote server, we have to run our application with jmx system properties. They are as follows:

  • com.sun.management.jmxremote.port to specify the port number through which the application will be exposed
  • com.sun.management.jmxremote.ssl to specify whether secure sockets layer (SSL) encryption will be activated to secure the connection to the application
  • com.sun.management.jmxremote.authenticate to specify whether the connection will be password protected

Jar command looks like:

 java -jar -Dcom.sun.management.jmxremote.port=1098 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false my-service.jar

 

Running JVisualVM on a Local Machine

I am an Ubuntu user and jvisualvm is available at:

 /usr/lib/jvm/java-8-oracle/bin/jvisualvm 

We can run jvisualVM using the following command in bash terminal as follows:

The application will launch as follows:

Create SOCKS Proxy Connection

The SOCKS proxy can be created either by SOCKS client or ssh utility on Linux.

We usedthe following command to create a secure tunnel between localhost and remote server:

ssh -fN -D 1098 my-username@my-remote-server-IP -pXXXX

-f option forks the process and tunnel create command runs in the background

-N option tells ssh that we don’t send any command once the tunnel setup

completed

-D option used to select the listening port

 -p  Port to connect to on the remote host

You will be asked password to set up the SOCKS proxy.

Add Proxy Setting in JVisualVM

Use following steps from the tools menu:

Tools->Options->Network – Manual Proxy Settings – check it and configure SOCKS Proxy at localhost and port 1098

Add Remote Host in JVisualVM

Use the following steps from the JVisualVM sidebar.

Right click on the remote host -> Add remote host -- Type the IP of the server

Note: I have added display name myserver to hide the serverIP

Add JMX Connection

Use following steps to add the JMX connection

Right click on myserver->Type the jmx port (add 1098)

Note: I have added display name myservice-on-myserver to hide the serverIP.

Collecting Stats

Now, we can analyze the collected stats like CPU usage, system properties, detailed Threads report with access to stack traces, CPU sampling, etc.

Final snapshot will be like as follows:


All the best on your JVisualVM endeavors!

application

Opinions expressed by DZone contributors are their own.

Related

  • Deployment of Spring MVC App on a Local Tomcat Server
  • Empowering Secure Access: Unleashing the Potential of Microsoft Entra ID Application Proxy
  • Testing Swing Application
  • Building A Simple AI Application in 2023 for Fun and Profit

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: