简体   繁体   中英

Find the memory allocated by the JVM

I am looking for an easy way to find out how much memory the JVM on my computer has allocated to a specific process, i have tried using VisualVM, but it cannot find the process.

I should mention that this it's running a Windows Service, not a regular process.

Any suggestions ?

Thank in advance.

I use in android (if you want to know a programatic way):

// get the total memory for my app
long total = Runtime.getRuntime().totalMemory();
// get the free memory available
long free = Runtime.getRuntime().freeMemory();

// some simple arithmetic to see how much i use
long used = total - free;

System.out.println("Used memory in bytes: " + used);

Works for the PC too(just tested)!

there is a command that comes with the JRE called jps which you can use to see all the running java processes. using jps with -v gives you the launch parameters of each process.

终奌站

You can see here the launch parameters which will tell you the memory usage of each process.

This command should run also on Windows, just replace the terminal with a command prompt.

JVisualVM should work for you. There are specific cases where the process is not shown in visualVM.

See some known issues

Local Applications Cannot Be Monitored (Error Dialog On Startup) Description: An error dialog saying that local applications cannot be monitored is shown immediately after VisualVM startup. Locally running Java applications are displayed as (pid ###). Resolution: This can happen on Windows systems if the username contains capitalized letters. In this case, username is UserName but the jvmstat directory created by JDK is %TMP%\\hsperfdata_username. To workaround the problem, exit all Java applications, delete the %TMP%\\hsperfdata_username directory and create new%TMP%\\hsperfdata_UserName directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM