About Java.lang.OutOfMemoryError:java Heap Space Error Solution
Source: Internet
Author: User
First check that the program has no limit to the dead loop
This problem is mainly caused by the problem Java.lang.OutOfMemoryError:Java heap space. The first time such a problem arises, other problems arise. A search on the web may be the reason why the Java stack setting is too small.
According to the answers on the internet, there are roughly two ways to solve this problem:
1. Set environment variable
Workaround: Manually set heap Size
Modify Tomcat_home/bin/catalina.sh
Set java_opts=-xms32m-xmx512m
You can make changes based on your machine's memory.
2, java-xms32m-xmx800m ClassName
is to add this parameter when executing the Java class file, where ClassName is required to perform a true class name. (including package name)
This solves the problem. And the speed of execution is much faster than when it is not set.
If you might use Eclispe at the time of the test, you would need to enter-xms32m-xmx800m This parameter in the VM arguments in Eclipse->run-arguments.
Later, the boot parameters were modified in Eclilpse, and-xms32m-xmx800m was added to the VM arguments to solve the problem.
First, Java.lang.OutOfMemoryError:PermGen space
PermGen space is the full name of the permanent Generation spaces, refers to the memory of the permanent storage area,
This memory is primarily stored in class and meta information by the JVM, and class is placed in PermGen space when it is loader.
Unlike the heap region where the class instance (Instance) is stored, the GC (garbage Collection) does not
PermGen space for cleaning, so if your application has a lot of class, it is likely to appear permgen space error,
This error is common when the Web server is pre compile the JSP. If your web app uses a lot of third-party jars, its size
This error message is generated if the JVM default size (4M) is exceeded.
Workaround: Manually set the MaxPermSize size
Modify Tomcat_home/bin/catalina.sh
In the "echo" Using catalina_base: $CATALINA _base "", add the following line:
Recommendation: Move the same third-party jar files to the Tomcat/shared/lib directory, which will reduce the memory consumption of the jar document.
Second, Java.lang.OutOfMemoryError:Java heap space
Heap Size Setting
The JVM heap setting is the setting of the memory space that the JVM can allocate to the Java program while it is running. The JVM automatically sets the value of heap size at startup.
Its initial space (i.e.-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 the-XMN-XMS-XMX provided by the JVM to
is set. 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 for GC and the available heap size is less than 2%.
Tip: Heap Size is not greater than 80% of the available physical memory, typically to set the-XMS and-XMX options to the same, and-xmn to the-XMX value of 1/4.
Workaround: Manually set heap Size
Modify Tomcat_home/bin/catalina.sh
In the "echo" Using catalina_base: $CATALINA _base "", add the following line:
Large Web engineering, the memory space allocated by Tomcat default cannot be started, and if Tomcat is not started in MyEclipse it can be set for Tomcat:
Tomcat_home\bin\catalina.bat Add this sentence:
Set java_opts=-xmx1024m-xms512m-xx:maxpermsize=256m
If you want to start in MyEclipse, the above changes will not work, you can set the following:
In the Myeclipse->preferences->myeclipse->servers->tomcat->tom catx.x->jdk panel
Add to Optional Java VM arguments:-xmx1024m-xms512m-xx:maxpermsize=256m Sea Willow cigarette holder Authentic
When you start Tomcat in MyEclipse, you are prompted to "Ava.lang.OutOfMemoryError:Java heap space" and the solution is:
In the Myeclipse->preferences->myeclipse->servers->tomcat->tom catx.x->jdk panel
Optional Java VM arguments add:-xmx1024m-xms512m-xx:maxpermsize=256m
Above is reproduced
The error I encountered was when I started Tomcat in MyEclipse, prompting "Ava.lang.OutOfMemoryError:Java Heap space"
I've tried all these three points, and I don't know where my code is going into the dead loop. I'm using struts,hibernate,spring.
According to the error prompts jsonwrite find the mapping file under Pojo under the hibernate of their own project
eg
There are two associated tables that generate two associated entity classes and mapping files Personinfomation and Stateoffice
Because mapping files and entity classes are generated automatically from database tables, bidirectional relationships are generated automatically
In the personinfomation private Persstateoffice persstateoffice;
And in the Stateoffice private set<perspersoninformation> perspersoninformations = new hashset< Perspersoninformation> (
0);
So when you encapsulate JSON data, there's a dead loop that's constantly encapsulated in two entity classes, resulting in a memory overflow
Solution 1 Canceling Association 2 in Stateoffice Manual encapsulation of JSON data (in order to avoid errors and conflicts with query data I choose to encapsulate the JSON data manually)
eg://get the type of appointment
Public String Loadofficetype () throws Exception {
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