Java 似乎忽略了 -Xms 和 -Xmx 选项

Java seems to ignore -Xms and -Xmx options(Java 似乎忽略了 -Xms 和 -Xmx 选项)

本文介绍了Java 似乎忽略了 -Xms 和 -Xmx 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 VPS 上运行一个用 java 编写的非常简单的机器人.我想将 jvm 内存限制为 10MB(我怀疑它是否需要更多).

I'd like to run a very simple bot written in java on my VPS. I want to limit jvm memory to let's say 10MB (I doubt it would need any more).

我正在使用以下命令运行机器人:

I'm running the bot with the following command:

java -Xms5M -Xmx10M -server -jarIrcBot.jar "/home/jbot"

java -Xms5M -Xmx10M -server -jar IrcBot.jar "/home/jbot"

但是 top 显示为 java 保留的实际内存是 144m (或者我在这里解释错了吗?).

But top shows that actual memory reserved for java is 144m (or am I interpreting things wrong here?).

13614 jbot 17 0 144m 16m 6740S 0.0 3.2 0:00.20 java

13614 jbot 17 0 144m 16m 6740 S 0.0 3.2 0:00.20 java

有什么想法可以在这里出错吗?

Any ideas what can be wrong here?

Java 版本1.6.0_20"Java(TM) SE 运行时环境(内部版本 1.6.0_20-b02)Java HotSpot(TM) 客户端 VM(内部版本 16.3-b01,混合模式)

Java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)

顺便说一句.我正在运行 CentOS - 如果重要的话.

BTW. I'm running CentOS - if it matters.

谢谢您的回答.

我真的不能接受其中任何一个,因为事实证明问题出在我选择编写程序的语言上,而不是 JVM 本身.

I can't really accept any of them, since it turns out the problem lies within the language i choose to write the program, not the JVM itself.

推荐答案

-Xmx 指定最大 Java heap 分配(-Xms 指定最小分配).Java 进程有自己的开销(实际的 JVM 等),加上加载的类和 perm gen 空间(通过 -XX:MaxPermSize=128m 设置)也在该值之外.

-Xmx specifies the max Java heap allocation (-Xms specifies the min heap allocation). The Java process has its own overhead (the actual JVM etc), plus the loaded classes and the perm gen space (set via -XX:MaxPermSize=128m) sits outside of that value too.

将您的堆分配简单地视为 Java 的内部工作空间",而不是整个进程.

Think of your heap allocation as simply Java's "internal working space", not the process as a whole.

尝试一下,你就会明白我的意思:

Try experimenting and you'll see what I mean:

java -Xms512m -Xmx1024m ...

另外,尝试使用 JConsoleJVisualVM 等工具(两者都随 Sun/Oracle JDK 提供),您将能够看到实际的堆使用情况(以及用于限制大小的设置).

Also, try using a tool such as JConsole or JVisualVM (both are shipped with the Sun / Oracle JDK) and you'll be able to see graphical representations of the actual heap usage (and the settings you used to constrain the size).

最后,正如@Peter Lawrey 非常正确地指出的那样,常驻内存是这里的关键数字 - 在您的情况下,JVM 仅使用 16 MiB RSS(根据顶部").只要 JVM 的堆没有被推入交换(非 RAM),共享/虚拟分配就不会引起任何问题.同样,正如我在一些评论中所说,还有其他可用的 JVM——Java"完全能够在低资源或嵌入式平台上运行.

Finally, as @Peter Lawrey very rightly states, the resident memory is the crucial figure here - in your case the JVM is only using 16 MiB RSS (according to 'top'). The shared / virtual allocation won't cause any issues as long as the JVM's heap isn't pushed into swap (non-RAM). Again, as I've stated in some of the comments, there are other JVM's available - "Java" is quite capable of running on low resource or embedded platforms.

这篇关于Java 似乎忽略了 -Xms 和 -Xmx 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java 似乎忽略了 -Xms 和 -Xmx 选项

基础教程推荐