tomcat memory overflow problem

Affirmation, positive Sina Weibo

http://blog.sina.com.cn/s/blog_7c76d639010118co.html

 

Memory overflow solution for tomcat startup

  (2011-12-25 11:40:01)
Label: 

miscellaneous talk

 

If you want to start in myeclipse, the above modification will not work, you can set it as follows:

Myeclipse->preferences->myeclipse->servers->tomcat->tomcat×.×->In the

Optional Java VM arguments in the JDK panel Add: -Xmx1024M -Xms512M -XX:MaxPermSize=256m


The service method I use is Tomcat, the memory is 2G, and my parameter settings in Configure Tomcat->JAVA->JAVA OPTIONS are:


-Xms500m
-Xmx1024m
-XX:PermSize=64M
-XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=48m
-Duser.timezone=GMT+08

//First check whether the program is limited to an infinite loop

. This problem is mainly caused by this problem java.lang.OutOfMemoryError: Java heap space. After the first occurrence of such a problem, other problems arose. A search on the Internet may be the reason why the JAVA stack setting is too small.
According to the answers on the Internet, there are roughly two solutions:
1. Set the environment variable
set JAVA_OPTS= -Xms32m -Xmx512m
can be changed according to the memory of your own machine.

2. java -Xms32m -Xmx800m className
is to add this parameter when executing the JAVA class file, where className is the class name that needs to be executed. (including package name)
This solved the problem. And the execution speed is much faster than when there is no setting.

If you may use Eclispe when testing, you need to enter the parameter -Xms32m -Xmx800m in the VM arguments in Eclipse -> run -arguments.

Later, the startup parameters were modified in Eclilpse, and -Xms32m -Xmx800m was added to the VM arguments, and the problem was solved.

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 main program runtime, so if your application has a lot of CLASS, 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 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
: Move the same third-party jar file to the tomcat/shared/lib directory, so as to reduce the repeated occupation of memory by the jar file.

II 、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 starts, and
its 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 set using options such as -Xmn -Xms -Xmx provided by the JVM. The
size of the Heap size is Young The sum of Generation and Tenured Generation.
Hint: In the JVM, if 98% of the time is used for GC and the available Heap size is less than 2%, this exception will be thrown.
Hint: The maximum Heap Size should not exceed 80 of the available physical memory %, in general, 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
and modify TOMCAT_HOME/bin/catalina.sh
in "echo "Using CATALINA_BASE: Add the following line above $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 "A

large web project cannot be started with the memory space allocated by tomcat by default. If tomcat is not started in myeclipse, you can set tomcat like this:

TOMCAT_HOME\bin\catalina.bat Add this sentence:

     

          set JAVA_OPTS= - Xmx1024M -Xms512M -XX:MaxPermSize=256m

Java Heap Management - Garbage Collection The following points are mentioned, which are very good, and may be used as a guideline when writing programs:

  (1) Don't try to assume the time when garbage collection occurs, all of which are is unknown. For example, a temporary object in a method becomes a useless object after the method is called, and its memory can be released at this time.

  (2) Java provides some classes that deal with garbage collection, and provides a method to enforce garbage collection - calling System.gc(), but this is also an uncertain method. In Java, there is no guarantee that garbage collection can be started every time this method is called. It just sends such an application to the JVM. Whether or not garbage collection is actually performed is unknown.

  (3) Choose a garbage collector that suits you. In general, if the system does not have special and demanding performance requirements, the JVM's default options can be used. Otherwise, you can consider using targeted garbage collectors, such as incremental collectors, which are more suitable for systems with high real-time requirements. If the system has a high configuration and has more idle resources, you can consider using a parallel mark/sweep collector.

  (4) The key and difficult to grasp problem is memory leak. Good programming habits and rigorous programming attitude are always the most important, don't let a small mistake lead to a big memory leak.

  (5) Release references to useless objects as soon as possible.
When most programmers use temporary variables, they make the reference variable automatically set to null after exiting the active scope (scope), implying the garbage collector to collect the object, and must also pay attention to whether the referenced object is monitored, If there is, remove the listener, and then assign a null value.

That is to say, for the operation of frequently applying for memory and releasing memory, it is better to control it yourself, but the method of System.gc() is not necessarily applicable. It is better to use finalize to enforce or write your own finalize method.

=================================================
Reprint java .lang.OutOfMemoryError: Java heap space solution Collection


java.lang.OutOfMemoryError: Java heap space solution

The root cause of this problem is that the default heap size of the jvm virtual machine is 64M, which can be achieved by setting its maximum and minimum values. Set There are mainly several methods.

1. You can change the system environment variable in windows
and add JAVA_OPTS=-Xms64m -Xmx512m

2. If you use tomcat, under windows, you can add it in

C:\tomcat5.5.9\bin\catalina.bat Above :

set JAVA_OPTS=-Xms64m -Xmx256m

The location is: rem Guess CATALINA_HOME if not defined Add appropriate below this line.

3. If it is a linux system , add set JAVA_OPTS='-Xms64 -Xmx512'
in front of {tomcat_home}/bin/catalina.sh

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325904458&siteId=291194637