Recently encountered Java program startup, error is as Follows:
Exception in thread "catalina-exec-1190" java.lang.OutOfMemoryError:PermGen spaceexception in Thread " catalina-exec-1198 "java.lang.OutOfMemoryError:PermGen spaceexception in thread" catalina-exec-102 " Java.lang.OutOfMemoryError:PermGen spaceexception in thread "catalina-exec-397" java.lang.OutOfMemoryError:PermGen Spaceexception in thread "catalina-exec-709" java.lang.OutOfMemoryError:PermGen space
The query found that the MaxPermSize settings are too small, adjusted to return to Normal. After the query Java memory overflow common error situation, organized as Follows:
Common Java memory overflows are listed in the following three ways:
1. Java.lang.OutOfMemoryError:Java heap Space----JVM heap (heap) Overflow
The JVM will automatically set the JVM heap value when it is started, and its initial space (that Is,-xms) is 1/64 of the physical memory, and the maximum space (-xmx) cannot exceed the physical memory.
You can use options such as THE-XMN-XMS-XMX provided by the JVM to set it up. The size of the heap is the sum of young Generation and tenured Generaion.
This exception information is thrown in the JVM if 98% of the time is used for gc, and the available heap size is less than 2%.
workaround : Manually set the size of the JVM heap (heap)
2. Java.lang.OutOfMemoryError:PermGen Space----permgen Space overflow.
The full name of PermGen space is permanent Generation space, which refers to the permanent storage area of memory.
Why memory overflow, This is because the memory is mainly stored by the JVM class and Meta information, class in the load is loaded into the PermGen space area, which is stored in the instance heap area, Sun The GC does not clean up permgen space during the main program's run time, so if your app loads many classes, There's a good chance that permgen space will overflow.
workaround : Manually set the MaxPermSize size
3. Java.lang.StackOverflowError----stack Overflow
Stack overflows, The JVM is still a stack-based virtual machine, which is the same as C and Pascal. The procedure for calling a function is on the stack and on the FALLBACK.
There are too many "layers" of calls to the constructor to overflow the stack Area.
Generally speaking, the general stack area is much smaller than the heap area, because the function call process is often not more than thousands of layers, and even if each function call requires 1K of space (this is approximately equivalent to a C function declared 256 int type variable), then the stack area is just need 1MB of space. The size of the stack is usually 1-2mb.
Often recursion does not have too many levels of recursion, it is easy to overflow.
Workaround : Modify the program
other, set the JVM memory usage method:
1. Tomcat under Linux:
Modify Tomcat_home/bin/catalina.sh
Location cygwin=false ago
java_opts= "-djava.awt.headless=true-dfile.encoding=utf-8-server-xms4096m-xmx4096m-xx:newsize=512m-xx: MAXNEWSIZE=512M-XX:PERMSIZE=512M-XX:MAXPERMSIZE=512M-XX:+DISABLEEXPLICITGC "
JVM parameter Description:
-server: must be the first parameter, good performance on multiple CPUs
-xms:java Heap Initial Size. Default is 1/64 of physical memory
-xmx:java Heap Maximum Value. The recommendation is set to half of physical memory and not more than physical memory.
-xx:permsize: sets the initial size of the Memory's permanent save, The default value is 64M.
-xx:maxpermsize: sets the maximum size of the Memory's permanent save, The default value is 64M.
-xx:survivorratio=2: the size of the survivor pool, default is 2, if garbage collection becomes a bottleneck, you can try to customize the build pool settings
-xx:newsize: the initial size of the newly generated Pool. The default value is 2M.
-xx:maxnewsize: the maximum size of the newly generated Pool. The default value is 32M.
If the JVM has a heap size greater than 1GB, you should use the value:-xx:newsize=640m-xx:maxnewsize=640m-xx:survivorratio=16, or allocate 50% to 60% of the total size of the heap to the newly generated Pool. Adjust the DA object area to reduce the number of full gc.
+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, "-XSS 15120" This causes JBoss to consume 15M of memory as soon as each additional thread is added (thread), and the best value should be 128K, and the default value seems to be 512k.
-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: Shorten major collection time this option is more appropriate if the heap size is large and major collection time is Longer.
-XX:USERPARNEWGC can be used to set up parallel collection "multi-cpu"
-xx:parallelgcthreads can be used to increase the degree of parallelism "multi-cpu"
-XX:USEPARALLELGC can be set to use parallel purge collector "multi-cpu"
Tomcat concurrency Optimization
1.Tomcat Connection Related parameters
The parameters related to the number of connections in the configuration in Server.xml in the Tomcat configuration file conf are:
Minprocessors: minimum number of idle connection threads for improved system processing performance with a default value of 10
Maxprocessors: Maximum number of connection threads, which is the maximum number of requests concurrently processed, with a default value of 75
Acceptcount: Maximum number of connections allowed, should be greater than or equal to maxprocessors, default value is 100
Enablelookups: whether to reverse the domain name, the value is: true or False. To improve processing power, set to False
Connectiontimeout: Network connection time-out, unit: MILLISECONDS. Set to 0 to never time out, so the setting is Hidden. It can usually be set to 30000 MILLISECONDS.
The default Tomcat parameters:
<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>
Modified To:
<connector port= "8080" protocol= "org.apache.coyote.http11.Http11NioProtocol" maxthreads= "minsparethreads=" "maxsparethreads=" "acceptcount=" "connectiontimeout=" 20000 "redirectport=" 8443 "/>"
Related instructions:
protocol= "org.apache.coyote.http11.Http11NioProtocol"///asynchronous IO Care technology using java, no blocking IO
Maxthreads= "600" indicates maximum simultaneous processing of 600 connections//maximum threads
Minsparethreads= "100" means that even if no one is using it, the number of threads that are created while waiting for//initialization is open for so many empty threads
maxsparethreads= "500" means that if you can empty up to 500 threads, such as 505 people at a time, and no one has access after that, Tomcat does not keep 505 empty threads, but turns off 505 Empty. Once you create a thread that exceeds this value, tomcat closes the socket thread that is no longer needed.
Acceptcount= "700"//specifies The number of requests that can be placed in the processing queue when all the threads that can be used to process the request are used, and requests that exceed this number will not be processed
This is an optimization of the HTTP connector, and if you use Apache and Tomcat to load balance the cluster and use the AJP protocol for Apache and Tomcat protocol forwarding, you also need to optimize the AJP Connector.
<connector port= "8009" protocol= "ajp/1.3" maxthreads= "" "minsparethreads=" maxsparethreads= "500" acceptcount= "connectiontimeout=" 20000 "redirectport=" 8443 "/>"
This article from the "day up goto" blog, Please be sure to keep this source http://ttxsgoto.blog.51cto.com/4943095/1851308
JVM settings in Java