java虚拟机内存不足,“CouldnotcreatetheJavaVirtualMach。。。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
java虚拟机内存不⾜,“CouldnotcreatetheJavaVirtualMach。
在运⾏java程序时,遇到问题"Could not create the Java Virtual Machine."如下截图:
⼤概原因,就是java堆内存不⾜以运⾏JVM,需要增加内存。
⽹上搜索此问题,⼤部分都是针对某个程序进⾏修改JVM内存的解决⽅法,⽐如eclipse,等。
试问,若是其他程序出现问题了呢?
现在给出⼀个全局的java虚拟机修改内存的⽅法。
在WIN XP,WIN 7,WIN8都可以。
解决⽅案:增加⼀个系统环境变量
变量名:_JAVA_OPTIONS
变量值:-Xmx512M
保存后,就OK!!
下⾯给出关于java堆内存的⼀个介绍,这是⼀个英⽂⽹页的翻译过来的。
关于java堆内存:
Java -Xmx is the configuration parameter to control the amount of memory Java uses on a system. Basically these settings are there to control the Heap memory size of Java. There are two settings related to Java heap memory:
-Xmx to set the maximum heap memory size
-Xms to set the minimum heap memory size
Tips to set the Java heap memory size
Managing the Java heap memory size for a server is very crucial as the whole performance depends on this memory size, off course there are other factors which affects the performance. So let’s see how you can set these parameters to control the Java heap memory size.
If you set -Xmx too small for your server then your application may not work properly and you may get Out of memory exception. So never set this too small as this is the maximum amount of memory you are allocating for Java and it cannot utilize memory beyond the set value.
It is always advisable to set -Xmx to a higher value if you have enough memory space available on your server. On the other hand if you set -Xmx value to a higher value your other resources will not be able to perform well as you have already reserved some of your memory for Java. So before setting the maximum heap size memory just check how much memory is free. To do so, stop your application server and check the free memory and accordingly you can set the maximum memory size. For example if you have 512M free memory then you can set heap memory to 300M safely i.e. -Xmx300m.
If you set -Xms to higher value you might run out of memory. So always try to keep it to a small value like -Xms16m. In tomcat when you restart the server it starts a Java process and that process takes the same -Xms as the default value for the tomcat and if it is higher you may get out of memory.
Now let’s see how to set java heap memory in different servers.
How to set java heap size in Tomcat
To set the java heap size in tomcat you need to edit the catalina.sh (On Linux) or catalina.bat (On Windows) file. You can find these files inside the bin directory of tomcat. Open the appropriate file and search for CATALINA_OPTS and set the value as shown below, you can change the max and min value to whatever you want.
set CATALINA_OPTS=-Xms64m -Xmx512m
export CATALINA_OPTS=”-Xms64m -Xmx512m”
setenv CATALINA_OPTS “-Xms64m -Xmx512m”
⼤概翻译如下:
Java - xmx配置参数控制Java系统上使⽤的内存量。
基本上这些设置有控制Java堆内存的⼤⼩。
有两种设置相关的Java堆内存:
- xmx设置最⼤的堆内存的⼤⼩
xms设置最⼩堆内存⼤⼩
建议设置Java堆内存⼤⼩
管理服务器的Java堆内存⼤⼩是⾮常重要的整个性能取决于这个内存⼤⼩,当然还有其他因素影响性能。
所以让我们来看看你可以设置这些参数来控制Java堆内存⼤⼩。
不设置- xmx太⼩价值
如果你为你的服务器设置- xmx太⼩,那么您的应⽤程序可能⽆法正常⼯作,你可能会得到内存不⾜异常。
所以不要设置过⼩,因为这是你们的最⼤内存分配为Java和它不能利⽤内存超出设定的值。
它总是明智的- xmx较⾼的值,如果你有⾜够的内存空间可⽤的服务器上。
另⼀⽅⾯如果你- xmx值设置为较⾼的值其他资源将⽆法执⾏以及你已经保留你的⼀些Java内存。
所以设置最⼤堆⼤⼩的内存之前就检查多少内存是免费的。
为此,停⽌应⽤服务器并检查空闲内存,因此您可以设置最⼤的内存⼤⼩。
例如,如果你有512的空闲内存,那么你可以设置堆内存300安全即-Xmx300m。
xms设置为⼀个较⼩的值
如果你设置xms更⾼的值可能会耗尽内存。
所以总是试图保持它像-Xms16m⼀个较⼩的值。
在tomcat中当你重新启动服务器,启动⼀个Java进程,过程需要相同的xms tomcat的默认值,如果它是更⾼的你可能会失去记忆。
现在让我们看看如何在不同的服务器上设置java堆内存。
如何设置Tomcat java堆⼤⼩
设置java堆⼤⼩在tomcat中您需要编辑catalina.sh(在Linux上)或catalina。
蝙蝠(在Windows上)⽂件。
你可以找到这些⽂件在tomcat的bin⽬录。
打开相应的⽂件和搜索CATALINA_OPTS和设置值如下所⽰,你可以改变任何你想要的最⼤和最⼩值。
设置CATALINA_OPTS = -Xms64m -Xmx512m
出⼝CATALINA_OPTS = " -Xms64m -Xmx512m”
setenv CATALINA_OPTS”-Xms64m -Xmx512m”。