5

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.

3 Answers 3

7

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.

terminal

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.

Sign up to request clarification or add additional context in comments.

4 Comments

does this command work directly from the CMD on windows ? or it should be exectued from a specific path ?
I don't know, I'm not using windows but I'm pretty sure you should be able to call it from any folder. It gives you back the running processes on the JVM which isn't folder specific.
Hey Bryan, it works on windows, just needs the path to Java home, thanks. For some reason this also cannot find it. i should mention that this it's running a Windows Service, not a regular process.
jps DOES NOT WORK if the target Java application is running as a service.
6

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)!

2 Comments

Yes, i just entered into eclipse. Of course you need a program to asociate the runtime to. To get the value in kB divide to 1024 etc... for other sizes
If the program is a Tomcat service, can i asociate it with it ?
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.