Java. lang. OutOfMemoryError solution, java. lang. error

Source: Internet
Author: User
Tags xms

Java. lang. OutOfMemoryError solution, java. lang. error

Cause: The following are common causes:

1. The amount of data loaded in the memory is too large, such as extracting too much data from the database at a time;

2. There are references to objects in the Collection class, which are not cleared after use, so that JVM cannot be recycled;

3. There are endless loops or loops in the code that generate too many repeated object entities;

4. Bugs in third-party software used;

5. The memory value of the startup parameter is set too small;

Common error codes: 1. tomcat: java. lang. OutOfMemoryError: PermGen space

2. tomcat: java. lang. OutOfMemoryError: Java heap space

3. weblogic: Root cause of ServletException java. lang. OutOfMemoryError

4. resin: java. lang. OutOfMemoryError

5. java: java. lang. OutOfMemoryError


Solution; 1. Solution to the application server error: Set the memory value of the startup parameter to a large enough value.

 

2. troubleshoot errors caused by Java code: troubleshoot the following points:

1) check whether there is an endless loop or recursive call in the code.

2) check whether there are large loops that repeatedly generate new object entities.

3) check whether all data is obtained once in the database query. Generally, if 100,000 records are retrieved to the memory at a time, memory overflow may occur. This problem is relatively hidden. Before going online, the database has less data and is not prone to problems. After going online, there is more data in the database, and a single query may cause memory overflow. Therefore, we recommend that you query the database by page.

4) Check whether List, MAP, and other collection objects are not cleared after use. List, MAP, and other collection objects always have references to objects, so that these objects cannot be recycled by GC.

Case: 1. When hibernate queries data, It queries too much data at a time, and then adjusts the code of this Part to retrieve only the specified amount of data at a time, successfully solving this problem. 2. During the stress test, an OutOfMemoryError occurs. It is found that the resources of the session have not been released. It is best to release the resources of the session through the invalidate () method of the session. 3. An endless loop occurs in the program. 4. When an OutOfMemoryError occurs during tomcat deployment and running, increase the memory parameter value to solve this problem.

 

Java. lang. OutOfMemoryError: Java heap space Exception Handling in tomcat

1. Heap size JVM Heap setting refers to the setting of memory space that JVM can allocate during java program running. the JVM automatically sets the Heap size value at startup. The initial space (-Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. You can use options such as-Xmn-Xms-Xmx provided by JVM to set the configuration. The Heap size is the sum of Young Generation and Tenured Generaion. Tip: if 98% is used for GC and the available Heap size is less than 2% in JVM, this exception is thrown. Tip: the Heap Size should not exceed 80% of the available physical memory. Generally, you must set the-Xms and-Xmx options to the same, and-Xmn to the-Xmx value of 1/4.

2. Solution: manually set Heap size to modify TOMCAT_HOME/bin/catalina. sh Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE ": JAVA_OPTS ="-server-Xms800m-Xmx800m-XX: MaxNewSize = 256 m"


Java. lang. OutOfMemoryError: PermGen space Exception Handling in tomcat

1. PermGen space the full name of PermGen space is Permanent Generation space, which refers to the Permanent storage area of the memory. This memory is mainly used by JVM to store Class and Meta information, when a Class is loaded, it will be placed in the PermGen space. It is different from the Heap region where the Class Instance is stored. GC (Garbage Collection) permGen space is not cleaned up during the main program running period. Therefore, if your application contains many classes, the PermGen space error may occur, this error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files and the size exceeds the default jvm size (4 MB), this error message is generated.

Solution: manually set MaxPermSize to modify TOMCAT_HOME/bin/catalina. sh Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE ": JAVA_OPTS ="-server-XX: PermSize = 64 M-XX: MaxPermSize = 128 m recommended: move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

 

Java. lang. OutOfMemoryError Exception Handling in weblogic

Error message: "Root cause of ervletException java. lang. OutOfMemoryError"

Solution: adjust the parameters in CommEnv in bea/weblogic/common: sun if "% PRODUCTION_MODE %" = "true" goto sun_prod_mode set JAVA_VM =-client set MEM_ARGS =-Xms256m-Xmx512m-XX: maxPermSize = 256 m set JAVA_OPTIONS = % JAVA_OPTIONS %-Xverify: none goto continue: sun_prod_mode set JAVA_VM =-server set MEM_ARGS =-Xms256m-memory-XX: MaxPermSize = 256 m goto continue

 

Java. lang. OutOfMemoryError: PermGen space exception handling when Eclipse runs Jboss

When running Jboss in Eclipse, sometimes java. lang. OutOfMemoryError: PermGen space may occur after a long time. Here we will introduce a solution:

1) Click the Small Arrow next to the debug icon;

2) Click "Debug deployments ..." Menu item;

3) Select "JBoss v4.2 at localhost" under the "Generic Server" tree on the left ";

4) Click the "Arguments" Tab on the right and add the following in "VM arguments:

-Dprogram. name = run. bat-Djava. endorsed. dirs = "D:/JBoss405/bin /.. /lib/endorsed "-Xms128m-Xmx512m-XX: PermSize = 64 m-XX: MaxPermSize = 256 m

5) if you use the command line mode or directly click "run. bat "to run JBoss, then you need to run in bin/run. modify the JVM option in the conf file and find JAVA_OPTS = "-Xms128m-Xmx512m ..." This section is followed by "-XX: PermSize = 64 m-XX: MaxPermSize = 256m ". Save and OK.

6) Note: The numbers 128, 512, 64, and 256 can be adjusted based on the configuration of your machine, and then click "Apply.

 

Exception Handling for java. lang. OutOfMemoryError in Resin

Cause: this error occurs because the JVM physical memory is too small. By default, the maximum memory size of the Java Virtual Machine is only 64 MB, which may be no problem during development and debugging, but it is far from sufficient in the actual application environment unless your application is very small, no traffic. Otherwise, you may find the java. lang. OutOfMemoryError package after the program runs for a period of time. Therefore, we need to increase the memory size of the resin available virtual machine.

Solution: Modify/usr/local/resin/bin/httpd. the args option in sh adds parameters-Xms (initial memory) and-Xmx (maximum memory size available) to limit the JVM's physical memory usage. For example, after args = "-Xms128m-Xmx256m" is set, the initial physical memory of JVM is 128 MB, and the maximum physical memory is 256 MB. These two values should be set by the system administrator based on the actual situation of the server.

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.