Memory measurement of Java application on Windows

Survey of Java memory usage

When you want to check the amount of memory actually used by a Java application under a Windows environment, you cannot check it on the Process tab of Task Manager. ** Task Manager shows the size of the memory allocated by the JVM as a whole. ** ** This time, I'll show you how to use two methods to get a rough idea of the size of memory that Java is actually using. By using this method, you can see the approximate amount of memory used without significantly affecting the processing without modifying the application.

1. How to use Jstat

For measuring the used memory using the jstat command, refer to Another article. ** You can also use the Jstat command from the command prompt in a Windows environment. ** In the Windows environment, the jstat.exe file exists in the bin folder of the JDK. Also, the process ID specified by the jstat command is the same value as the task manager PID.

2. How to use jvisualvm

For GUI environment, by using ** Java VisualVM (jvisualvm) ** You can easily check the memory usage. ** jvisualvm is a tool that illustrates data about Java applications in a format that allows you to quickly browse. ** Explains how to measure memory using this tool.

Install jvisualvm

Like jstat, this tool comes with the Oracle JDK from the beginning. The jvisualvm.exe file exists in the bin folder of the JDK. If you can't find it, download it from the Official Site (https://visualvm.github.io/).

Monitoring JVM memory with jvisualvm

Let's check the heap memory usage of the JAVA app. First, start jvisualvm in advance. Then start the application for which you want to check the memory. When you start the app, the launched app will be displayed in the list of java apps on the left, so click it. visualVM

Click the "Monitor" tab to see various graphs about the JVM. When checking the heap memory, the graph on the upper right is displayed. You can check the current used heap size in an easy-to-understand graph display.

visualVM(グラフ)

Detailed check of used memory

One thing to note is that the size of the "used heap" in the heap graph above ** is a mixture of data that is actually used at that time and data that is no longer used but remains in memory. I will. ** If you want to see the size of the heap actually used, you only need to check the amount of data actually used in it. You can check the actual memory used by paying attention to the timing after the occurrence of full GC. For details, refer to Jstat article.

Add GC information

You can check the status of GC by adding a plugin to the app. Open a window with Tools ⇒ Plugins and select the Available Plugins tag. Add the ** "Visual GC" ** plugin from among several plugins. If the addition is successful, a new tab called "Visual GC" will be added. By selecting this tab, you can also check the status of GC in a graph. visualVM(GC)

Precautions when using jvisualvm

jvisualvm specializes in quickly graphically displaying various data related to the JVM. Therefore, ** It is not possible to specify the display range of the graph or output numerical values, so it is not suitable for detailed investigation. ** Use jvisualvm if you want to easily check the real-time information of the app that is currently running. If you want to investigate in a little more detail, you should use the method using jstat properly.

Recommended Posts

Memory measurement of Java application on Windows
Volume of trying to create a Java Web application on Windows Server 2016
Install Java with zip on Windows
Install Java 9 on windows 10 and CentOS 7
Develop gRPC on Windows + Java 7 + Maven 2
Memory measurement for Java apps using jstat
Examine the memory usage of Java elements
Using JupyterLab + Java with WSL on Windows 10
Status monitoring of java application using Elasticsearch
Looking back on the basics of Java
Building Java Web Applications on Windows Server 2016
Role of JSP in Web application [Java]
Build Web Application Server (Java) on VPS
[Java development] Java memory
Java 9+ application status
Switch between multiple versions of Java on Mac
I touched on the new features of Java 15
[Solution] Java cannot be installed on Windows 10 + ATOK 2017
[Java] Overview of Java
I tried running a DB access application on IKS + Db2 on IBM Cloud (6. Preparation of DB access application (java))
As of April 2018 How to get Java 8 on Mac
Java SE Development Kit (JDK) setup procedure on Windows
Java coverage measurement library
Predicted Features of Java
Let's touch on Java
Install Corretto 8 on Windows
[Java] Significance of serialVersionUID
Install Java on Mac
Review of java Shilber
Accurate time measurement (Java)
Run PostgreSQL on Java
java --Unification of comments
History of Java annotation
java (merits of polymorphism)
NIO review of java
M.S. docker on Windows
Correspondence when Java application exed by launch4j does not work on windows with openJDK installed
[Java] Three features of Java
Summary of Java support 2018
Story of making a task management application with swing, java
20190803_Java & k8s on Azure The story of going to the festival
Use Java Web Start in an OpenJDK environment on Windows
Using multiple versions of Java with Brew on Mac + jEnv
About regular execution of rake task of rails application on heroku
[Java] Difference between Stack Overflow Error and Out Of Memory Error