Tomcat memory cannot be released

Tomcat memory cannot be released

Today the company's CMS tomcat crashed again, and it crashed once. The following error occurred, and then the memory of tomcat was increased to 1024
severe: Exception initializing page context
java.lang.OutOfMemoryError: Java heap space is

in tomcat\bin\catalina. bat's set CURRENT_DIR=%cd% before adding
set JAVA_OPTS =-Xms512m -Xmx1024m
meaning: set the minimum virtual memory of 512, the maximum of 1024.

Today tomcat is down again, and under investigation, it is found that the memory only rises and does not fall. It's dead. In addition, you can use a java management tool to view the memory usage. In jdk1.6.0\bin\jconsole.exe.

Summarize several reasons why the memory only rises and does not fall:
1. Although there is garbage collection in java But the garbage generated by rs and others accessing the database through jdbc is not collected!
2. Whether it is due to too many layers of cyclic sockets that the resources cannot be released, or there is an infinite loop, the possibility of the latter is high.
3. Tomcat does not support the development of EJB components. When doing j2ee projects, it is best to use weblogic services, and when doing basic sql statements, it is best to use connection pools. Do not use jdbc and odbc bridges because the most important The time-consuming

solution is to let tomcat manage the memory by itself, add the following code under @echo off in startup.bat:
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager =org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_HOME%\conf\logging.properties"

and then start startup.bat, tomcat will manage memory by itself.

In fact, this It is an optimization. Because for the operating system, the system call requesting memory will take up a lot of cpu time, so frequent requests and release of memory will cause a serious drop in performance. So for JVM, the best way is to take up as much memory as the heap as much as possible, and release less or even not release the idle heap to the operating system to reduce the cpu time consumed in memory requests and release operations.
The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​the memory. OutOfMemoryError: PermGen space is a memory gain on the surface. The solution must be to increase the memory. Talk about why the memory is profitable: This part is used to store the information of the Class and Meta. The Class is placed in 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 PermGen space is cleaned up during the main program runtime, so if your APP loads a lot of CLASS, PermGen space errors are likely to occur. This kind of error is common when the web server pre-compiles the JSP.

Correction method: -Xms256m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

For -XX:MaxNewSize=256m -XX:MaxPermSize=256m friends who have questions can go to: http://hi.baidu.com /charlesyy/blog/item/b89b5dee30cfdaf9b2fb95d5.html  

Guess you like

Origin blog.csdn.net/yucaifu1989/article/details/107708389