Several common memory overflows in Java and their solutions

Several common memory overflows in ava and their solutions [Case 1]:
java.lang.OutOfMemoryError: Javaheapspace: This is that the java heap memory is not enough, one reason is that it is really not enough (such as too many recursive layers, etc.), another reason There is an infinite loop in the program;
  if the java heap memory is not enough, it can be solved by adjusting the following configuration of the JVM:
  -Xms3062m
  -Xmx3062m
[Case 2]
  java.lang.OutOfMemoryError:GCoverheadlimitexceeded
  [Explanation]: JDK6 adds a new error type, Thrown when the GC takes a lot of time to release a small space; usually because the heap is too small, causing the exception, there is not enough memory.
  [Solution]:
  1. Check whether the system has code that uses large memory or an infinite loop;
  2. Limit the use of memory by adding JVM configuration:
  -XX:-UseGCOverheadLimit
[Case 3]:
  java.lang.OutOfMemoryError: PermGenspace: This is because the memory in the P area is not enough, you can adjust the JVM configuration:
  -XX:MaxPermSize=128m
  -XXermSize=128m
  [Note]:
  The Perm area of ​​the JVM is mainly used to store Class and Meta information. When the Class is loaded by the Loader, it will be placed in the PermGenspace. This area becomes the old generation. The GC will not clean up the old area during the running of the main program. The default is 64M Size, when the program needs to load more objects, more than 64M will report that this part of the memory overflows, you need to increase the memory allocation, generally 128M is enough.
[Case 4]:
  java.lang.OutOfMemoryError: Directbuffermemory
  adjustment -XX:MaxDirectMemorySize= parameter, such as adding JVM configuration:
  -XX:MaxDirectMemorySize=128m
[Case 5]:
  java.lang.OutOfMemoryError:unabletocreatenewnativethread
  [Cause]: insufficient stack space To create additional threads, either too many threads are created, or the Stack space is really small.
  [Solution]: Since the JVM does not provide parameters to set the total stack space size, it can set the size of a single thread stack; while the user space of the system is 3G in total, except for the Text/Data/BSS/MemoryMapping segments, Heap and The total amount of stack space is limited, and it is one of the other. Therefore, if you encounter this error, you can solve it in two ways: 1. Reduce the stack size of a single thread through the -Xss startup parameter, so that more threads can be opened (of course, it cannot be too small, and a StackOverflowError will appear); 2. Through- The two parameters of Xms-Xmx reduce the size of the Heap and give the memory to the Stack (provided that the Heap space is sufficient).
[Case 6]:
  java.lang.StackOverflowError
  [Cause]: This is also a type of memory overflow error, that is, the overflow of the thread stack, either because there are too many method calls (such as infinite recursive calls), or the thread stack is too small.
  [Solution]: Optimize the program design and reduce the method call level; adjust the -Xss parameter to increase the thread stack size.

Guess you like

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