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.
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.
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.
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/).
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.
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.
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.
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.
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