Tomcat catalina.sh java_opts parameter description and configuration

Source: Internet
Author: User
Tags xms

The Ox-man writes the JVM's blog:

http://blog.csdn.net/java2000_wl/article/category/1249100

http://blog.csdn.net/cutesource/article/details/5904501

There are several links:

http://www.cnblogs.com/fantiantian/p/3623740.html See what the Tomcat boot files are doing. Catalina.bat

http://www.cnblogs.com/bluestorm/archive/2013/04/23/3037392.html Tomcat's JVM settings and number of connections settings
http://blog.chinaunix.net/uid-26602509-id-4110244.html memory Overflow Tomcat memory configuration-catalina.sh or Catalina.bat

http://www.wangmeng.net.cn/?p=53 Tomcat Memory Overflow (Windows startup Tomcat Service has no effect after modifying Catalina.bat)

http://blog.csdn.net/sun8288/article/details/8161813 JVM Settings related to Windows under the Tomcat service

A recent project on hand has reported a memory overflow error, and a memory overflow (out of memofy) is referred to as the legendary Oom. ^_^ Online Search for information to learn the next java_opts parameters and configuration, applied to the production environment, no further error.

Error message: Java.lang.OutOfMemoryError:Java heap Space

Test environment: Rhel5.4_x64

Jdk-6u20-linux-x64.bin

apache-tomcat-6.0.20

Production environment: Windows Server Enterprise Edition

Jdk-6u21-windows-x64

apache-tomcat-6.0.29

Linux Modify catalina.sh File

java_opts= "-server-dfile.encoding=utf-8-XMS=512M-XMX1024M-XX:PERMSIZE=128M-XX:MAXPERMSIZE=256M-VERBOSE:GC- Xloggc:${catalina_home}/logs/gc.log ' Date +%y-%m-%d-%h-%m '-xx:+useconcmarksweepgc-xx:+cmsincrementalmode-xx:+ PRINTGCDETAILS-XX:+PRINTGCTIMESTAMPS-NOCLASSGC "

Windows modifies Catalina.bat files

Set java_opts=-server-xms1024m-xmx2048m-xx:permsize=256m-xx:maxpermsize=512m

Total Memory:java The amount of memory that the virtual machine is using that has been dug from the system, that is, all the memory occupied by the Java Virtual machine process at that time. If you do not add the-XMS parameter when running Java, then, in the Java program running process, memory is always slowly dug from the operating system, basically how much digging, until the maxmemory (), so totalmemory () is slowly increasing. If the-XMS parameter is used, the program will start with unconditional digging from the operating system-XMS the amount of memory defined behind it, and then dig it when the memory is about the same.

Max Memory:java virtual machine can be dug from the operating system to the maximum memory size, if you run a Java program, do not add the-XMX parameter, then the default is 64 trillion, which is the Java Virtual machine by default can be dug from the operating system of the largest memory. If the-XMX parameter is added, it is recommended to set it to half of memory, whichever is the value after this parameter.

Free memory: Just said that if you run Java without adding the-XMS parameter, then, in the Java program running process, memory is always slowly from the operating system dug, basically how much digging how much, these dug up and no use of memory, is actually Freememory, so the value of freememory is generally very small, but if you run a Java program using the-XMS, this time because the program at boot time will be unconditionally dug from the operating system-XMS later defined memory number, this time, The memory dug up may be largely useless, so this time freememory may be a bit bigger.

JVM Memory Setting Method:

The Linux system directly edits the tomcat_home/bin/catalina.sh file, as shown in the file above, and no longer says much.

1. Under Windows System, the installed version of Tomcat can start the "Configure Tomcat"--"Java" option configuration as shown in:

In addition to installing the JDK when the operating system is 64-bit, the installation of the JDK must be 64-bit, or can not be started. The jdk_home path is specified when Tomcat is installed. As shown in the following:

2, the green version of Tomcat, directly modify the Catalina.bat file, and the Linux system is not the same, the Windows System environment variable settings at the beginning of the set command, the Linux system Shell runtime will export environment variables.

Set java_opts=-server-xms1024m-xmx2048m-xx:permsize=256m-xx:maxpermsize=512m

Parameter description:

-server: Must be the first parameter, good performance on multiple CPUs

-XMS: Initial heap size, minimum memory used, higher CPU performance This value should be set to a larger

-xmx:java heap maximum, maximum memory used

-xx:permsize: Setting a permanent storage area for memory

-xx:maxpermsize: Set a permanent storage area for maximum memory

-xx:maxnewsize:

+xx:aggressiveheap will make XMS meaningless. This parameter allows the JVM to ignore the XMX parameter, frantically eating a g of physical memory, and then eating a G swap.

-XSS: Stack size per thread

-VERBOSE:GC Reality Garbage Collection Information

-xloggc:gc.log specifying garbage collection log files

The heap size of the-xmn:young generation, typically set to one of the 3, 4 points of Xmx

-XX:+USEPARNEWGC: Shortening the time of minor collection

-XX:+USECONCMARKSWEEPGC: Shortening the time of major collection

Tip: This option is more appropriate if the heap size is large and the major collection time is longer.

A solution to the JVM memory overflow problem with Tomcat

1, the first is: Java.lang.OutOfMemoryError:Java heap space

Explain:

The JVM heap setting is the set of memory space that the JVM can provision during the run of the Java program. The JVM automatically sets the value of the heap size when it starts, and its initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up. The size of Heap size is the sum of young Generation and tenured generaion.

Tip: This exception message is thrown in the JVM if 98% of the time is used for GC and the available heap size is less than 2%.

Tip: The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMX value of-xmn is 1/4.

Workaround:

Manually setting the heap size

To modify the Tomcat_home/bin/catalina.bat, add the following line above the "echo" Using catalina_base: $CATALINA _base "":

Set java_opts=%java_opts%-server-xms800m-xmx800m-xx:maxnewsize=256m

2, followed by: Java.lang.OutOfMemoryError:PermGen space

Reason:

PermGen space is the full name of permanent Generation space, refers to the memory of the permanent storage area, this block of memory is mainly stored by the JVM class and meta information, class is loader will be placed in PermGen Space, unlike the heap area where the class instance (Instance) is stored, the GC (garbage Collection) does not clean up permgen space during the main program run time, so if you have a class in your application, PermGen space errors are most likely to occur when the Web server pre-compile the JSP. If you have a large number of third-party jars under your web app that are larger than the JVM's default size (4M), this error message will be generated.

Workaround:

Manually setting the MaxPermSize size

Modify the Tomcat_home/bin/catalina.bat (under Linux for catalina.sh) and add the following line on the "echo" Using catalina_base: $CATALINA _base "":

Set java_opts=%java_opts%-server-xx:permsize=128m-xx:maxpermsize=512m

catalina.sh Add set java_opts= '-xms64-xmx512 ' Invalid solution

Set java_opts= '-xms64-xmx512 '
If the above is invalid, write this:
Declare-x java_opts= "-xms128m-xmx256"
"Declare-x" must be added, otherwise it will be reported that the-X command is invalid,
Also note that after adding WQ, after you restart Tomcat, PS Ax to see that the Tomcat process will become similar
/opt/jdk1.6.0/bin/java-xms128m-xmx256m-djava.endorsed.dirs=/opt/tomcat/common/e

Under Windows, if you use the console, that is, directly execute the startup.bat mode, you can modify the Catalina.bat
Set java_opts=-xms256m-xmx512m
Note that there is a single quotation mark under Linux, and win does not, and if you add a single quotation mark, Tomcat does not get up at all.

Tomcat catalina.sh java_opts parameter description and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.