General oom may be as follows:
1, Outofmemoryerror:java heap space;
2, Outofmemoryerror:permgen space;
3. Outofmemoryerror:unable to create new native thread
For the 1th and 2nd cases, the JVM parameters (Xms-xmx-xx:permsize-xx:maxpermsize) can be set to adjust processing.
Problem 3 occurs because we create too many threads, and the number of threads that can be created is limited, causing the exception to occur. The number of threads that can be created is calculated as follows:
Number of threads= (maxprocessmemory-jvmmemory-reservedosmemory)/(Threadstacksize)
Where: Maxprocessmemory refers to the maximum memory of a process
Jvmmemory JVM Memory
Reservedosmemory reserved Operating system memory
Size of the Threadstacksize line stacks
In the Java language, when you create a thread, the virtual opportunity creates a thread object in the JVM memory to create an operating system threads, and the system thread's memory is not jvmmemory, but the remaining memory in the system (Maxprocessmemory- Jvmmemory-reservedosmemory).
with the above example, let's illustrate the formula:
Maxprocessmemory under 32-bit Windows is 2G
jvmmemory Eclipse The program memory that is started by default is 64M
reservedosmemory is generally around 130M
formula is as follows: (2*1024*1024-64*1024-130*1024)/325 = 5841
formula calculated 5841, and practice 5602 basically consistent (biased because reservedosmemory is not very accurate)
Span style= "FONT-SIZE:14PX;" The is derived from the formula: < Span style= "FONT-SIZE:14PX;" >
Gee, a little bit of our common sense, well, let us verify, still use the above test program, plus the following JVM parameters, the test results are as follows:
Span style= "color: #000000; font-size:14px; " >
a) if there is a bug in the program that causes the creation of a large number of unwanted threads or the thread is not recycled in a timely manner, the bug must be fixed and the parameter modification cannot solve the problem;
b) If the program does require a large number of threads and the existing settings do not meet the requirements, you can increase the number of threads that can be created by modifying the maxprocessmemory,jvmmemory,threadstacksize three factors:
maxprocessmemory using 64-bit operating systems
JVMMemory Reduce jvmmemory allocations
threadstacksize reduce the stack size of a single thread
JVM oom Processing