PermGen space and its solution

java.lang.OutOfMemoryError: PermGen space and its solutions
Category : java 2007-09-11 12:34 38072 people read comments (18) Collection Report
PermGen space's full name is Permanent Generation space, which refers to the permanent storage area of ​​memory OutOfMemoryError: PermGen space is, on the surface, the benefit of memory, and the solution must be to increase the memory. Talk about why the memory will come out: This part is used to store the information of Class and Meta. The Class is put into the PermGen space area when it is loaded. It is different from the Heap area where the Instance is stored, and the GC (Garbage Collection) will not be in the area. The PermGen space is cleaned up during the running of the main program, so if your APP loads a lot of CLASS, it is likely to have a PermGen space error. This kind of error is common when the web server precompiles the JSP. Correction method: -Xms256m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m 2. An outofmemory error occurs when redeploying in tomcat. There can be the following reasons:
1. Proxool is used, because proxool contains An old version of cglib.
2, log4j, it is best not to use only common-logging
3, the old version of cglib, hurry up and update to the latest version.
4. Update to the latest hibernate3.2 3.

Take the tomcat environment as an example, other WEB servers such as jboss, weblogic, etc. are the same.
1. java.lang.OutOfMemoryError: PermGen space The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory. This memory is mainly used by JVM to store Class and Meta information, and Class will be placed when it is loaded by Loader. In the PermGen space, it is different from the Heap area where the class instance (Instance) is stored. GC (Garbage Collection) will not clean up the PermGen space during the runtime of the main program, so if there are many CLASS in your application, it is very likely A PermGen space error occurs, which is common when the web server precompiles the JSP. If your WEB APP uses a large number of third-party jars, the size of which exceeds the default size of jvm (4M), then this error message will be generated.
Solution: Manually set MaxPermSize size Modify TOMCAT_HOME/bin/catalina.sh Add the following line above "echo "Using CATALINA_BASE: $CATALINA_BASE"": JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128mSuggestion
: Move the same third-party jar files to the tomcat/shared/lib directory, so as to reduce the memory occupied by the jar files repeatedly.
2. java.lang.OutOfMemoryError: Java heap space Heap size Setting the setting of the JVM heap refers to the setting of the memory space that the JVM can allocate and use during the running of the java program. The JVM will automatically set the value of the Heap size when it is started, and its initial The space (i.e. -Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. It can be set by using options such as -Xmn -Xms -Xmx provided by the JVM. The size of Heap size is the sum of Young Generation and Tenured Generation. Hint: This exception will be thrown if 98% of the time in the JVM is used for GC and the available Heap size is less than 2%. Tip: The maximum Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same, and -Xmn is 1/4 of the -Xmx value.
Solution: Manually set the Heap size, modify TOMCAT_HOME/bin/catalina.sh and add the following line above "echo "Using CATALINA_BASE: $CATALINA_BASE"": JAVA_OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=256m"
3. Example , the parameter setting reference of java jvm in 1G memory environment is given below: JAVA_OPTS="-server -Xms800m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true "



java.lang.OutOfMemoryError exception solution
Reason :
Common are the following:
1.
2. There is a reference to the object in the collection class, and it is not emptied after use, so that the JVM cannot be recycled;
3. There is an infinite loop in the code or the loop produces too many repeated object entities;
4. BUG in the third-party software used;
5. The memory value of the startup parameter is set too small;

common error
messages: 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. The application server prompts error solution:
Set the startup parameter memory value to be large enough.
2. Resolution of errors caused by Java code:
focus on the following points:
1) Check whether there is an infinite loop or recursive call in the code.
2) Check if there is a large loop that repeatedly generates new object entities.
3) Check whether there is a query to obtain all data at one time in the database query. Generally speaking, if 100,000 records are fetched into memory at a time, it may cause memory overflow. This problem is relatively hidden. Before going online, there is less data in the database, and it is not easy to cause problems. After going online, there is a lot of data in the database, and a single query may cause memory overflow. Therefore, for database queries, try to use paging methods to query.
4) Check whether the collection objects such as List and MAP are not cleared after use. Collection objects such as List and MAP will always have references to objects, so that these objects cannot be recycled by GC.

Case:
1. When hibernate queried data, it queried too much data at one time, and then adjusted the code of this part, and only took out the specified amount of data each time, which successfully solved the problem.
2. During the stress test, an OutOfMemoryError occurs, and 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 infinite loop occurs in the program.
4. OutOfMemoryError occurs during tomcat deployment and operation, increase the memory parameter value to solve this problem.
java.lang.OutOfMemoryError: Java heap space exception handling in tomcat
1. Heap size
The setting of the JVM heap refers to the setting of the memory space that the JVM can allocate and use during the running of the java program. The JVM will automatically set the value of the Heap size when it starts. ,
the initial space (ie -Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. It can
be . The size of Heap size is the sum of Young Generation and Tenured Generation.
Hint: This exception will be thrown if 98% of the time in the JVM is used for GC and the available Heap size is less than 2%.
Tip: The maximum Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same, and -Xmn is 1/4 of the -Xmx value.

2. Solution: Manually set the Heap size
and modify TOMCAT_HOME/bin/catalina.sh
Add the following line to "echo "Using CATALINA_BASE: $CATALINA_BASE"":
JAVA_OPTS="-server -Xms800m -Xmx800m -XX:MaxNewSize=256m"
tomcat In java.lang.OutOfMemoryError: PermGen space exception handling
1.
PermGen space The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory.
This memory is mainly used by JVM to store Class and Meta information, and Class is stored by Loader It will be placed in the PermGen space,
which is different from the Heap area where the class instance (Instance) is stored. GC (Garbage Collection) will not
clean up the PermGen space during the runtime of the main program, so if your application has a lot of CLASS If so, it is very likely that there will be a PermGen space error,
which is common when the web server precompiles the JSP. If your WEB APP uses a lot of third-party jars, the size of which
exceeds the default size of jvm (4M), then this error message will be generated.
Solution: Manually set the MaxPermSize size
Modify TOMCAT_HOME/bin/catalina.sh
Add the following line above "echo "Using CATALINA_BASE: $CATALINA_BASE"":
JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128mSuggestion
: relocate the same third-party jar file to tomcat/shared/lib In this way, the purpose of reducing the memory occupied by jar documents can be achieved.
java.lang.OutOfMemoryError exception handling in weblogic
Error prompt:
"Root cause of ervletException java.lang.OutOfMemoryError"
Solution:
Adjust CommEnv in bea/weblogic/common Parameters
   : sun
  if "%PRODUCTION_MODE%" == "true" goto sun_prod_mode
  set JAVA_VM=-client
  set MEM_ARGS=-Xms256m -Xmx512m -XX:MaxPermSize=256m
  set JAVA_OPTIONS=%JAVA_OPTIONS% -Xverify:none
  goto continue
  :sun_prod_mode
  set JAVA_VM =-server
  set MEM_ARGS=-Xms256m -Xmx512m -XX:MaxPermSize=256m
  goto continue
java.lang.OutOfMemoryError: PermGen space exception handling
when Eclipse runs Jboss When running Jboss in Eclipse, if the time is too long, an error of java.lang.OutOfMemoryError: PermGen space may sometimes appear. Here is a solution for you :
1) Click the small arrow next to the debug icon;
2) Click the "Debug Configurations..." menu item;
3) Select "JBoss v4.2 at localhost" under the "Generic Server" tree on the left;
4) Click "Arguments" on the right "Tab", add in "VM arguments":
-Dprogram.name=run.bat -Djava.endorsed.dirs="D:/JBoss405/bin/../lib/endorsed" -Xms128m -Xmx512m -XX: PermSize=64m -XX:MaxPermSize=256m
5) If you run JBoss in command line mode or directly click "run.bat", then you need to modify the JVM options in the bin/run.conf file, find JAVA_OPTS="-Xms128m -Xmx512m..." This paragraph, then add "-XX:PermSize=64m -XX:MaxPermSize=256m" after it. Save is OK.
6) Note: The numbers 128, 512, 64 and 256 can be adjusted according to the configuration of your own machine, and then click "Apply".
java.lang.OutOfMemoryError exception handling under Resin
Reason:
This error occurs, generally because the JVM physical memory is too small. The default maximum memory of the Java virtual machine is only 64 megabytes, which may be no problem during development and debugging, but it is far from enough in the actual application environment, unless your application is very small and has little access. Otherwise you may find errors in the package java.lang.OutOfMemoryError after the program runs for a while. Therefore we need to increase the size of the virtual machine memory available to resin.
Solution:
Modify the args option in /usr/local/resin/bin/httpd.sh
Add parameters -Xms (initial memory) and -Xmx (maximum memory size
that can be used) to limit the physical memory usage of the JVM.
For example: After
args="-Xms128m -Xmx256m"
is set, the initial physical memory of the JVM is 128m, and the maximum physical memory that can be used is 256m.
These two values ​​should be set by the system administrator according to the actual situation of the server.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641610&siteId=291194637