如何正确设置java堆大小

时间:2015-07-06 10:37:37

标签: java

我开始使用Alfresco系统。我的电脑是32位的。我有一个问题:

 [exec]  T E S T S  
 [exec] Error occurred during initialization of VM
 [exec] Could not reserve enough space for object heap
 [exec] Error: Could not create the Java Virtual Machine.
 [exec] Error: A fatal exception has occurred. Program will exit.
 [exec] Results :
 [exec] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
 [exec] [INFO] Total time: 8.556 s
 [exec] [INFO] Finished at: 2015-07-06T12:12:51+02:00
 [exec] [INFO] Final Memory: 27M/64M
 [exec] [INFO] ------------------------------------------------------------------------
 [exec] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project spring-surf-core: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
 [exec] [ERROR] Command was cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_79\jre\bin\java" -Xmx2G -XX:MaxPermSize=256m -Duser.language=en -Dcom.sun.management.jmxremote -jar C:\alfr\alfresco\projects\surf\spring-surf-core\spring-surf-core\target\surefire\surefirebooter1762228666106185177.jar C:\alfr\alfresco\projects\surf\spring-surf-core\spring-surf-core\target\surefire\surefire5748163713411457336tmp C:\alfr\alfresco\projects\surf\spring-surf-core\spring-surf-core\target\surefire\surefire_04790546620732481422tmp"
 [exec] [ERROR] -> [Help 1]
 [exec] [ERROR] 
 [exec] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 [exec] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [exec] [ERROR] 
 [exec] [ERROR] For more information about the errors and possible solutions, please read the following articles:
 [exec] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
 [exec] [ERROR] 
 [exec] [ERROR] After correcting the problems, you can resume the build with the command
 [exec] [ERROR]   mvn <goals> -rf :spring-surf-core

BUILD FAILED
C:\alfr\alfresco\build.xml:46: exec returned: 1

我正在尝试eclipse.ini中的每个堆大小,但它仍然是相同的。我有4GB内存。

我应该如何设置XmxXms

2 个答案:

答案 0 :(得分:0)

我可以看到你使用maven来运行它然后你应该试试这个:

set MAVEN_OPTS=-Xmx512m  

或者你可以尝试

 set MAVEN_OPTS=-Xmx1024m

在Windows中,您可以设置环境变量MAVEN_OPTS并使用选定的值设置其值

答案 1 :(得分:0)

JVM告诉你它无法为对象堆保留足够的空间&#34;,这意味着你的-Xmx很可能设置得太大。

从您的命令来看,您似乎正在尝试使用2G,这可能比您的32位JVM可以处理的更多。

Oracle FAQs表明32位JVM的最大值介于1.4G和1.6G之间:

  

为什么我不能使用32位JVM获得更大的堆?

     

32位JVM的最大理论堆限制为4G。由于   各种附加约束,例如可用交换,内核地址   在实践中,空间使用,内存碎片和VM开销   限制可以低很多。在大多数现代32位Windows系统上   最大堆大小将介于1.4G到1.6G之间。在32位Solaris上   内核的地址空间限制为2G。在64位操作   运行32位VM的系统,最大堆大小可以更高,   在许多Solaris系统上接近4G。

您应该尝试较小的-Xmx设置,可能是1024m左右。我不能告诉你最佳设置,因为这取决于具体的任务,甚至可能会更少(JVM也会告诉你它是否用完堆内存)。