The first OutOfMemoryError: PermGen space.
The original intention of this problem is that a large number of jars or classes are used in the program, which makes the space for loading classes in the java virtual machine insufficient, which is related to the permanent generation space. There are two ways to solve this kind of problem:
1. Increase the size of XX:PermSize and XX:MaxPermSize parameters in the java virtual machine, where XX:PermSize is the initial persistent storage size and XX:MaxPermSize is the maximum persistent storage size. For tomcat6.0, add a line (about 70 lines) at the end of a series of environment variable names in the catalina.sh or catalina.bat file:
JAVA _ OPTS = "-XX:PermSize = 64M-XX:MaxPermSize = 128m "
If it is a windows server, it can also be set in the system environment variable. I feel that this kind of memory overflow error is easy to occur when using tomcat to publish programs with sprint+struts+hibernate architecture. Using the above method, I successfully solved the problem that tomcat server deploying ssh project often goes down.
2. clean up the jar under web-inf/lib in the application. If tomcat deploys multiple applications and many applications use the same jar, you can move the jar with * * * to the lib with Tomcat * * to reduce the repeated loading of classes.
The second out-of-memory error: Java heap space
The reason for this problem is that the java virtual machine creates too many objects, and the heap memory space allocated by the virtual machine has been used up before garbage collection, which is related to the heap space. There are two ways to solve this kind of problem:
1. Check the program to see if there is an infinite loop or unnecessary repeated creation of a large number of objects. After finding the reason, modify the program and algorithm.
When I used to write a K-Means text clustering algorithm to cluster tens of thousands of text records (the feature vector of each record is about 10), the memory overflow problem in Java heap space was caused by some problems in program details, and it was later solved by modifying the program.
2. Increase the size of Xms (initial heap size) and Xmx (maximum heap size) parameters in Java virtual machine. For example, set Java _ opts =-xms256m-xmx1024m.
The third out-of-memory error: unable to create a new native thread
This kind of error is easy to happen when there are many Java threads.