Analysis of causes and solutions of Java.lang.OutOfMemoryError:Java heap space

Source: Internet
Author: User
Tags xms

Explain:


The JVM heap setting is the set of memory space that the JVM can provision in the course of running the Java program. The JVM automatically sets the value of heapsize when it is started, and its initial space (that is,-XMS) is 1/64 of physical memory, and the maximum space (-XMX) is 1/4 of physical memory.


You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up. The size of the heapsize is the sum of younggeneration and tenuredgeneraion. This exception information is thrown in the JVM if 98% of the time is used for GC and the available heapsize is less than 2%.


Tips:


HeapSize maximum do not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and-xmn is a-xmx value of 1/4. The maximum heap size in the JVM has three limitations: the data Model (32-BT or 64-bit) of the associated operating system, the system's available virtual memory limits, and the available physical memory limits for the system. Under the 32-bit system, the 1.5g~2g;64 is generally limited to memory unrestricted for the operating system. I am in the WindowsServer2003 system, 3.5G physical memory, JDK5.0 under test, the maximum can be set to 1478m.

Summary of parameters


-XMS: Represents the size of the initial memory allocation for the Java Virtual machine heap memory, typically 1/64 of the operating system's available memory, but still needs to be allocated in the actual situation. It's possible that the design of the software has not been able to run and hang up when it is actually distributed according to such a rule. -XMX: Represents the maximum amount of Java Virtual machine heap memory that can be allocated, typically 1/4 of the operating system's available memory. However, in the development process, the-XMS is typically configured with the same value as the-xmx two parameter, which is intended to waste resources after the Java garbage collection mechanism does not need to re-partition the size of the compute heap after the heap is cleaned up.


In general, for the memory allocation of the heap area only need to the above-xms and-xmx two parameters reasonable configuration, but if you want to do more fine allocation can also be more granular memory of the heap area, it is necessary to use the following three parameters-xx:newsize,-xx:maxnewsize ,-xmn. Of course, this stems from the further refinement of the heap area: Cenozoic, Mesozoic, Laosheng generation. The memory space occupied by each new object in Java is the Cenozoic space, and when the Java garbage collection mechanism recycles the heap, the resources that are not reclaimed in the Cenozoic are transferred to the Mesozoic, and the Mesozoic is transferred to the Laosheng generation. The next three parameters to be described are used to control the size of the new generation of memory.


-xx:newsize: Indicates the new generation of initial memory size, should be less than the value of-XMS;
-xx:maxnewsize: Represents the maximum amount of memory that can be allocated in the Cenozoic, and of course the value should be less than the value of-xmx;

-XMN: As for this parameter is the-xx:newsize,-xx:maxnewsize two parameters of the simultaneous configuration, that is, if the new generation of memory by-XMN to configurethe size, then-xx:newsize=-XX: MAXNEWSIZE=-XMN, although it will be convenient, but it is important to note that this parameter is used after the JDK1.4 version


The above describes the parameters of the configurable heap area provided by the Java Virtual machine, followed by the two parameters of the Java virtual machine to the non-heap memory configuration:
-xx:permsize: Represents the non-heap initial memory allocation size, abbreviated to Permanentsize (persisted memory)-xx:maxpermsize: Represents the maximum upper limit of memory allocated for non-heap extents.


Various operating Environmental Solutions


Set HeapSize manually


Linux Platforms


To modify tomcat_home/bin/catalina.sh, add the following parameter to the "Cygwin=false" line: java_opts= "-XMS512M-XMX512M-XX:PERMSIZE=128M-XX: maxpermsize=256m "
The first way of Windows platform Tomcat installation:
Open the Registry (command: regedit), modify the registry hkey_local_machine\software\apachesoftwarefoundation\tomcatservicemanager\tomcat6\ Parameters\java\options

Add in the back:-xms512m-xmx512m xx:permsize=128m-xx:maxpermsize=256m-dcom.sun.management.jmxremote=true


The second way:
Click Apply "Tomcat6w.exe", find "Java" tab, add the above parameters in "Javaoptions"


Windows platform Tomcat decompression version


The first line in the file Catalina.bat file is added as follows:
setjava_opts=-xms512m-xmx512m-xx:maxnewsize=256m-xx:maxpermsize=256m

Analysis of causes and solutions of Java.lang.OutOfMemoryError:Java heap space

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.