4 ways to configure stack memory for different scopes of JVM!
1. Set JVM memory in Eclise: Modifies Eclipse's configuration file , works for all projects
Modify the Eclipse.ini file under the Eclipse root directory
-vmargs// Virtual machine Settings
-xms40m// Initial Memory
-xmx256m// Maximum Memory
-xmn16m// Minimum Memory
-xx:permsize=128m// non-heap memory
-xx:maxpermsize=256m
2.set JVM memory in Eclise : JREs VM Arguments parameter settings, works for all projects
open eclipse window-preferences-java-installed jres-edit-default VM Arguments
Enter in the VM argument:-xmx128m-xms64m-xmn32m-xss16m
3. set JVM memory in Eclise :runconfigurations VM arguments parameter setting , only works on this project
In Eclipse-right-click project/Main class to run-->run as-->runconfigurations--> (x) =ARGUMENTS-->VM Arguments
Join in -xmx36m
then Apply-->runThe above 36 refers to the maximum heap memory allocated to the Java virtual machine, in megabytes (MB), meaning that the maximum heap memory of the JVM is 36MB
4.set JVM memory in Eclise :Debug configurations VM arguments parameter setting, only works on this project
In Eclipse-right-click project/Main class to run-->debug as-->debugconfigurations--> (x) =ARGUMENTS-->VM Arguments
Add -xmx36m in
then Apply-->runThe above 36 refers to the maximum heap memory allocated to the Java virtual machine, in megabytes (MB), meaning that the maximum heap memory of the JVM is 36MB
5. Tomcat Memory settings
The first line in Catalina.bat is incremented under windows:
JAVA code:Set java_opts=-xms64m-xmx256m-xx:permsize=128m-xx:maxnewsize=256m-xx:maxpermsize=256m
The first line in catalina.sh is increased under Linux:
JAVA Code: java_opts=-xms64m-xmx256m-xx:permsize=128m-xx:maxnewsize=256m-xx:maxpermsize=256m
Example + detailed
Setting the initial memory for Tomcat boot its initial space (that is,-XMS) is 1/64 of physical memory, and the maximum space (-XMX) is 1/4 of physical memory.
Can be set with options such as-XMN-XMS-XMX provided by the JVM
example, the following is a reference to the parameter settings for a Java JVM in a 1G memory environment:
Java_opts= "-server-xms800m-xmx800m-xx:permsize=64m-xx:maxnewsize=256m-xx:maxpermsize=128m-djava.awt.headless= True "
Java_opts= "-server-xms768m-xmx768m-xx:permsize=128m-xx:maxpermsize=256m-xx:newsize=192m-xx:maxnewsize=384m"
Catalina_opts= "-server-xms768m-xmx768m-xx:permsize=128m-xx:maxpermsize=256m-xx:newsize=192m-xx:maxnewsize=384m "
Linux:
In the/usr/local/apache-tomcat-5.5.23/bin directory, add the catalina.sh:
Java_opts= '-xms512m-xmx1024m ' to add "M" description is MB, otherwise it is KB, when starting Tomcat will be reported insufficient memory.
-XMS: Initial value-xmx: Maximum value-xmn: Minimum value
Windows:
Add set java_opts=-xms128m-xmx350m at the front of the Catalina.bat
If the Tomcat,ok setting is in effect with Startup.bat startup. Enough to allocate 200M of memory successfully.
However, if you do not execute startup.bat to start Tomcat but use Windows system services to start the Tomcat service, the settings above do not take effect, meaning set java_opts=-xms128m-xmx350m It didn't work. Allocate 200M of memory above to Oom.
The Windows service performs bin\tomcat.exe. He reads the value in the registry instead of the Catalina.bat setting.
Workaround:
Modify the registry Hkey_local_machine\software\apache software Foundation\tomcat Service manager\tomcat5\parameters\javaoptions
The original value is-dcatalina.home= "C:\ApacheGroup\Tomcat 5.0"-djava.endorsed.dirs= "C:\ApacheGroup\Tomcat 5.0\common\endorsed"- XRS Join-xms300m-xmx350m
Restart Tomcat service, set to take effect
Solution to Tomcat's JVM memory overflow problem: Tomcat's JVM memory overflow problem Resolution
Recently in the familiar with a project that has been developed for several years, the need to transfer the database from MySQL to Oracle, the first point of the JDBC connection to MySQL, packaged into Tomcat inside, can run, no problem, but when the JDBC connection point to Oracle, Tomcat on the continuous throw java.lang.OutOfMemoryError error, internet Google a bit, understand the operation of Tomcat, also solve the problem, share out, for reference.
1, the first is: Java.lang.OutOfMemoryError:Java heap space explained:
The heap size setting of the JVM heap is the setting of the memory space that the JVM can provision in the run of the Java program. The JVM automatically sets the value of the heap size when it starts, and its initial space (that is,-XMS) is 1/64 of the physical memory, the maximum space (-XMX) is 1/4 of the physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up. The size of Heap size is the sum of young Generation and tenured generaion.
Tip: This exception message is thrown in the JVM if 98% of the time is used for GC and the available heap size is less than 2%.
Tip: The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.
Workaround:
Manually set the heap size to modify Tomcat_home/bin/catalina.bat, add the following line on the "echo" Using catalina_base: $CATALINA _base "":
JAVA Code Set java_opts=%java_opts%-server-xms800m-xmx800m-xx:maxnewsize=256m
or modify catalina.sh in the "echo" Using catalina_base: $CATALINA _base "" Add the following line: java_opts= "$JAVA _opts-server-xms800m-xmx800m- xx:maxnewsize=256m "
2, followed by: Java.lang.OutOfMemoryError:PermGen space Reason:
PermGen space is the full name of permanent Generation space, refers to the memory of the permanent storage area, this block of memory is mainly stored by the JVM class and meta information, class is loader will be placed in PermGen Space, unlike the heap area where the class instance (Instance) is stored, the GC (garbage Collection) does not clean up permgen space during the main program run time, so if you have a class in your application, PermGen space errors are most likely to occur when the Web server pre-compile the JSP. If you have a large number of third-party jars under your web app that are larger than the JVM's default size (4M), this error message will be generated.
Workaround:
1. Manually set MaxPermSize size modification Tomcat_home/bin/catalina.bat (Linux under Catalina.sh), in Java code "echo" Using catalina_base: $ Catalina_base "" Add the following line: Set java_opts=%java_opts%-server-xx:permsize=128m-xx:maxpermsize=512m
catalina.sh: JAVA code java_opts= "$JAVA _opts-server-xx:permsize=128m-xx:maxpermsize=512m"
JVM heap memory stack memory size setting