In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "what is the method of Tomcat memory configuration", the content is detailed, the steps are clear, the details are handled properly, I hope this article "what is the method of Tomcat memory configuration" can help you solve your doubts, the following follows the editor's ideas slowly in depth, together to learn new knowledge.
1. Background
The special remarks of this article only introduce the memory allocation based on HotSpot VM virtual machine and JDK1.7. The statement about GC is also based on CMS's concurrent collection (not G1) to prevent Bull Pat Brick.
At present, the mainstream JVM is HotSpot VM (followed by J9 VM,Zing VM). At present, most of the blog posts are based on the previous version of JDK1.7.
(note: because of different virtual machine implementations and different JDK, the distribution of memory is different, that is to say, the memory structure mentioned in the following article is only logical structure, not physical structure of memory)
two。 Overall memory structure
If you just want to solve the problem and don't want to know why, please skip this chapter.
This article introduces the structure of the memory area of garbage collection (referred to as GC heap, excluding program counters, stacks, and local method stacks), quoting the saying "the lifetime of a java object".
I am an ordinary Java object, I was born in the Eden area, in the Eden area I also saw a little brother who looks like me (other java objects), and we played in the Eden area for a long time. One day there were so many people in Eden (Young GC will be triggered, every time GC plus one year old), I was forced to go to the "From" area of Survivor. Since I went to Survivor, I began to float. Sometimes in the "From" area of Survivor, sometimes in the "To" area of Survivor, there is no fixed residence (every time Young GC needs a "swap" between from and to in Survivor). Until I was 18 years old (after 18 Young GC sessions), my father said that I was an adult and that it was time for me to venture into society. So I went to the old generation, there are a lot of people in the old generation, and they are all very old, and I know a lot of people here. In the older generation, I lived for 20 years and was Old GC.
To explain, first of all, the memory is generally divided into the younger generation (young), the old generation (old), and the * generation (permanent), as shown in the following figure
Younger generation: (for the younger generation of garbage collection, we are referred to as Young GC)
The younger generation is divided into eden area and survivor area.
The 1.eden area, which is new Object (), where the object was born.
2.survivor area is the surviving object storage area after garbage collection, and the survivor area is divided into from area and to area.
2.1.from area: after GC recycling, objects still alive in eden area and to area will be stored in from area.
2.2.to area: after GC recycling, objects that are still alive in eden area and from area will be transferred to to area
2.3. Because of the operation of 2.1and 2.2, the living objects in the from and to regions are transferred back and forth, and one zone is always empty.
Old age: (garbage collection for the old era referred to as Old GC)
After 18 times of Young GC, the surviving objects of the younger generation will be transferred from the younger generation to the old age.
When the old age expires, Old GC will be triggered, and the surviving objects will remain in the old age until they are recycled after 20 times of Old GC.
* * Generation: (for the recycling of the younger generation + the older generation + the * generation is referred to as Full GC)
Is an implementation of HotSpot VM for the Java method area, which usually stores data such as class information, constant pools, static variables, JIT compiled code, etc. (simply understood as the storage area of compiled code, that is, it can be understood as: when our java project runs, the more class files loaded, the more memory space is needed.)
(note: the * * generation is said to be a unique concept of the Hotspot virtual machine, and no other JVM has this concept. In Java 8, the * generation is completely removed and replaced by another piece of local memory that is not connected to the heap-metaspace)
3. General explanation of memory problem
FAQ 1: java.lang.OutOfMemoryError: Java heap space-JVM Heap (heap) overflow
Reason: during the running phase of the project, the new has too many objects and is full of configured memory. This error will occur.
Solution: manually set the size of Xms and Xmx.
FAQ 2 java.lang.OutOfMemoryError: PermGen space-PermGen space (* generation) overflow
Reason: this error occurs when there are many Java files in the project (that is, the project is very large and a lot of files are loaded by JVM).
Solution: set the MaxPermSize size manually.
FAQ 3 java.lang.StackOverflowError-stack overflow
Reason: it is usually caused by too many levels of recursion in the logic of a code.
Solution: modify the recursive code and control the number of recursive layers
4. Memory allocation method (recommended, not *)
This article only introduces some commonly used configuration parameters. In general, the * generation does not count as heap memory (occupies another piece of memory separately). The new generation accounts for 1x2 of the older generation, that is, 1max 3 of the entire heap memory. According to this principle, we give a configuration example.
For example, the server can provide 1 GB of memory for the project. According to the figure above, we give the following configuration.
Operation mode:
-server server mode, with better performance in the case of multiple CPU
New generation and old age: (usually the new generation and the old age are not configured separately, so you can directly configure the entire memory heap size)
-initial memory space of the Xms384m memory heap
-Xmx768m memory heap * memory space
* Generation: (the new generation, the remaining memory of the old configuration is left for the * generation)-note that jdk1.8 has been removed
-XX:PermSize=128m * generation initialization size
-memory space of XX:MaxPermSize=256m * generation * (default is 64m)
4. Memory configuration methods of Tomcat in different environments
All kinds of memory problems have been explained in detail and configuration parameters have been briefly introduced. Let's introduce the specific configuration methods in various environments.
1. Use the tomcat started by the command line:
Modify TOMCAT_HOME/bin/catalina.sh (catalina.bat in windows) by adding the following statement at the top of the file
JAVA_OPTS= "- server-Xms384m-Xmx768m-XX:PermSize=128m-XX:MaxPermSize=256m"
two。 If tomcat is registered as a windows service, use the / bin/tomcat8w.exe in the tomcat directory to modify it. The figure below is as follows
3. If you are using myeclipse to start tomcat, the above changes will not work and can be set as follows:
Myeclipse- > preferences- > myeclipse- > servers- > tomcat- > tomcat ×. ×-> add the following to the Optional Java VM arguments in the JDK panel:
-server-Xms384m-Xmx768m-XX:PermSize=128m-XX:MaxPermSize=256m
After reading this, the article "what is the method of Tomcat memory configuration" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Https://app.yinxiang.com/fx/26611639-2495-4bf0-9233-74c1ad98f64a
© 2024 shulou.com SLNews company. All rights reserved.