Java programmers have not encountered OutOfMemory is simply impossible!
Can be seen in the Java world, too many uncertainties to run Java programs directly result in the collapse of a direct throw OutOfMemory exception, and once encountered this problem, investigated, very difficult. In JDK 5.0 before, OutOfMemory only such a sentence: java.lang.OutOfMemory Exception ... basically no start, no way of analysis. From JDK 5.0 on OutOfMemory after a number of additional detailed description of the analysis for this exception provides great convenience.
The problems that will throw OutOfMemory: PermGen Space exception, this exception is very interesting, according to this article】 【description, this is a Sun JVM's bug, since 2003, an up to now no solution . And the proposed solution is to use JRockit. Bug causes have been found, because JVM PermGen Space in the distribution of the time there PermGen Space shortage, by default PermGen size is 64M, not for use in the case of JRockit, you can add a start time JVM parameters:-XX: MaxPermSize = 128m | 256m | 512m.
So what is a PermGen it?
PermGen in fact refer to Permanent Generation, itself is in Java's garbage collection mechanism (GC) generated in concept. Java's garbage collection mechanism is through all the objects first, if we find an object is not referenced, then the recovery, which is in the early Java 1.0 and Java 1.1, when the GC rules. Slowly, such a "stupid" GC algorithm JVM performance became a bottleneck, have large amounts of data in Java applications, GC of the algorithm is highly enhanced, so a variety of efficient algorithms have been developed JVM GC up. J2SE is Java 1.2 from the beginning, JVM introduced a wide range of GC algorithms, one of which is used a lot of Generational Collection, Chinese is called " points on behalf of the collection method . "
Collecting points on behalf of the rejection of all objects traversal, but with some experience in property to avoid extra work (While naive garbage collection examines every live object in the heap, generational collection exploits several empirically observed properties of most applications to avoid extra work ). Which imported the concept of a critical: infant mortality (infant mortality), this means that the more the new generation of variable or object, the more easily be collected. The following figure shows an object life cycle, the horizontal axis that is the test to the object's life cycle, the vertical axis indicates the life cycle on a specified number of objects to be recovered.
Can see that the points on behalf of the collection method used after the object is to collect the young generation of the highest rates. And the object in memory will be in accordance with the different "ages" to divide, when the object of a full age after age in the garbage collection will occur on, starting from the younger generation has been to the "eternal generation" , in memory, all objects can be divided into many generations, the last generation of "eternal generation" is the "Permanent Generation", here is a direct lead to "Permanent Generation" concept of place. Specifically to refer to the diagram:
According to the situation said earlier in the sub-cases on behalf of garbage collection will have the concept of Permanent Generation, and this sub-generation of garbage collection method is a collection of parallel and concurrent basis to collect, so Permanent Generation will always exist, then the Permanent Generation Is What are they used for? Save the JVM where the class of all objects, including information like metadata, as well as methods of description, etc., so this generation of memory garbage collection algorithm is not the same as in the case of large program Java, especially J2EE or Java EE applications on large-scale, Permanent Generation of size can be loaded directly limit the number and size of the class.
】 【Solution is to set the JVM startup parameters, you can set up as follows:
java-XX: PermSize = 64m-XX: MaxPermSize = 128m
Also PermSize and MaxPermSize if the same can also be set to a certain extent, improve performance, because, PermSize in constant change which will need to transfer the data. If fixed later, you can reduce the time to expand PermSize performance loss.
See more 】 【Java Official site
In addition, you can also add the following Java startup parameters see GC's operation:
Tomcat directly start normally, start by myeclipse tomcat out of memory.
MyEclipse start Tomcat ignore catalina.bat set memory size of the problem.
Set in the tomcat's catalina.bat set JAVA_OPTS =- Xms128m-Xmx256m, directly startup.bat start tomcat without problems.
However, configure myeclipse tomcat, passed myeclipse of memory start to appear, before catalina.bat set of memory seems to have no effect.
Settings needed to be done can be solved as follows:
MyEclipse -> Window -> Preference ... -> MyEclipse -> Application Servers ->
Tomcat -> Tomcat 6.X -> JDK -> Optional Java VM arguments: set
Set the content:-Xms256m-Xmx512m
-Dcom.sun.management.jmxremote = true