Java 如何增加JVM内存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2294268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I increase the JVM memory?
提问by giri
HI, I like to know can I increase the memory of the JVM depending on my application.If yes how can I increase the JVM memory? And how can I know the size of JVM?
嗨,我想知道我可以根据我的应用程序增加 JVM 的内存。如果是,我该如何增加 JVM 内存?我怎么知道JVM的大小?
回答by Jeff Beck
When calling java use the -Xmx Flag for example -Xmx512m for 512 megs for the heap size. You may also want to consider the -xms flag to start the heap larger if you are going to have it grow right from the start. The default size is 128megs.
调用 java 时,使用 -Xmx 标志,例如 -Xmx512m 表示堆大小为 512 megs。如果您希望从一开始就让它增长,您可能还需要考虑使用 -xms 标志来启动更大的堆。默认大小为 128megs。
回答by hodgesmr
When starting the JVM, two parameters can be adjusted to suit your memory needs :
启动 JVM 时,可以调整两个参数以满足您的内存需求:
-Xms<size>
specifies the initial Java heap size and
指定初始 Java 堆大小和
-Xmx<size>
the maximum Java heap size.
最大 Java 堆大小。
回答by GuruKulki
If you are using Eclipse then you can do this by specifying the required size for the particular application in its Run Configuration's VM Arguments as EX: -Xms128m -Xmx512m
如果您使用的是 Eclipse,那么您可以通过在其运行配置的 VM 参数中将特定应用程序所需的大小指定为 EX: -Xms128m -Xmx512m
Or if you want all applications running from your eclipse to have the same specified size then you can specify this in the eclipse.ini
file which is present in your Eclipse home directory.
或者,如果您希望从 Eclipse 运行的所有应用程序具有相同的指定大小,那么您可以eclipse.ini
在 Eclipse 主目录中的文件中指定它。
To get the size of the JVM during Runtime you can use Runtime.totalMemory()
which returns the total amount of memory in the Java virtual machine, measured in bytes.
要在运行时获取 JVM 的大小,您可以使用Runtime.totalMemory()
它返回 Java 虚拟机中的内存总量,以字节为单位。
回答by Mind Peace
Right click on project -> Run As -> Run Configurations..-> Select Arguments tab -> In VM Arguments you can increase your JVM memory allocation. Java HotSpot document will help you to setup your VM Argument HERE
右键单击项目 -> 运行方式 -> 运行配置..-> 选择参数选项卡 -> 在 VM 参数中,您可以增加 JVM 内存分配。Java HotSpot 文档将帮助您在此处设置 VM 参数
I will not prefer to make any changes into eclipse.ini as minor mistake cause lot of issues. It's easier to play with VM Args
我不希望对 eclipse.ini 进行任何更改,因为小错误会导致很多问题。使用 VM Args 更简单