简体   繁体   English

找到JVM分配的内存

[英]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. 我正在寻找一种简单的方法来找出我的计算机上的JVM分配给特定进程的内存量,我已经尝试过使用VisualVM,但它无法找到该进程。

I should mention that this it's running a Windows Service, not a regular process. 我应该提一下,它正在运行Windows服务,而不是常规流程。

Any suggestions ? 有什么建议么 ?

Thank in advance. 预先感谢。

I use in android (if you want to know a programatic way): 我在android中使用(如果你想知道一种编程方式):

// 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)! 适用于PC(刚刚测试过)!

there is a command that comes with the JRE called jps which you can use to see all the running java processes. 有一个名为jps的JRE附带的命令,您可以使用它来查看所有正在运行的java进程。 using jps with -v gives you the launch parameters of each process. 使用带-v jps每个进程的启动参数。

终奌站

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. 此命令也应该在Windows上运行,只需用命令提示符替换终端。

JVisualVM should work for you. JVisualVM应该适合你。 There are specific cases where the process is not shown in visualVM. 在某些特定情况下,该过程未在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. 无法监视本地应用程序(启动时出现错误对话框)说明:VisualVM启动后会立即显示一个错误对话框,指出无法监视本地应用程序。 Locally running Java applications are displayed as (pid ###). 本地运行的Java应用程序显示为(pid ###)。 Resolution: This can happen on Windows systems if the username contains capitalized letters. 解决方案:如果用户名包含大写字母,则可能会在Windows系统上发生此问题。 In this case, username is UserName but the jvmstat directory created by JDK is %TMP%\\hsperfdata_username. 在这种情况下,username是UserName,但JDK创建的jvmstat目录是%TMP%\\ hsperfdata_username。 To workaround the problem, exit all Java applications, delete the %TMP%\\hsperfdata_username directory and create new%TMP%\\hsperfdata_UserName directory. 要解决此问题,请退出所有Java应用程序,删除%TMP%\\ hsperfdata_username目录并创建新的%TMP%\\ hsperfdata_UserName目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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