如何使用命令行为JAVA分配空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20714804/
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 to allocate space to JAVA using command line
提问by Alice Everett
I have come across heap errors while loading a large dataset into Jena. `Is there some way by which I may allocate the JVM(Java) a large heap space.
我在将大型数据集加载到 Jena 时遇到了堆错误。`有什么方法可以为JVM(Java)分配一个大的堆空间。
I know I can achieve this by making changes into eclipse.ini. But is there some way by which I may increase the Java heap size using command line in linux (I using a 64GB RAM server: running 12.04 Ubuntu LTS server)?
我知道我可以通过对 eclipse.ini 进行更改来实现这一点。但是有什么方法可以在 linux 中使用命令行增加 Java 堆大小(我使用 64GB RAM 服务器:运行 12.04 Ubuntu LTS 服务器)?
The error which I am getting due to less heap space is: exception in thread main gc overhead limit exceeded.
由于堆空间较少,我得到的错误是:超出线程主 gc 开销限制中的异常。
Also how can I find the maximum amount of heap space which I can set for my systems
另外,如何找到可以为系统设置的最大堆空间量
I tried export JAVA_OPTS= -Xms4096m -Xmx4096m but ended up getting the error:
bash: export: -Xms4096m': not a valid identifier
bash: export:
-Xmx4096m': not a valid identifier
我尝试 export JAVA_OPTS= -Xms4096m -Xmx4096m 但最终得到错误:bash: export: -Xms4096m': not a valid identifier
bash: export:
-Xmx4096m': not a valid identifier
采纳答案by Elliott Frisch
Try (note quotes are not optional with two words)
尝试(注意引号不是可选的两个词)
export JAVA_OPTS="-Xms4096m -Xmx4096m"
Or, even
甚至
export MIN="4096m" # <-- Those quotes are (one word).
export MAX="4096m"
export JAVA_OPTS="-Xms$MIN -Xmx$MAX" # <-- single quotes would break variable expansion
回答by oconnecp
java -Xms4096m -Xmx4096m [YourAppHere]
This command will allocate 4GB (or 4096 MB) of heap memory at the start (the -Xms4096m option), and will have a maximum heap memory size of 4GB (the -Xmx4096m option).
此命令将在开始时分配 4GB(或 4096 MB)堆内存(-Xms4096m 选项),最大堆内存大小为 4GB(-Xmx4096m 选项)。
Obviously you can change the number to whatever sizes you want to. There is overhead if the computer has to increase the size of memory (Every time it increases the memory size, it doubles the allocation) so if you have that much ram, you might as well just allocate it at the beginning of the app.
显然,您可以将数字更改为您想要的任何大小。如果计算机必须增加内存大小(每次增加内存大小,都会使分配增加一倍),则存在开销,因此如果您有那么多内存,您不妨在应用程序的开头分配它。