java.lang.OutOfMemoryError:unable to create new native thread

In this case, it is impossible to create a local thread, which is generally caused by insufficient operating system memory.

 

According to the OOM exception information: Unable to create a new local thread, it is known that the local thread cannot meet the use of the existing application. The memory allocation of threads belongs to the stack area, and the size of the stack area changes dynamically , which is the remaining available size after the system memory is allocated to the JVM and its own system reserves the running memory .

Assuming that we set -Xms -Xmx5G, it is conservatively estimated that the system reserves 500M running memory, and the total system memory is 8G

At this time, the remaining memory value is 8-5.5=2.5G. Therefore, only 2.5g of memory is left for creating threads. According to the thread stack size of -Xss defaulting to 1M, more than 2500 threads can be created. (Execute java -XX:+PrintFlagsFinal -version | grep ThreadStackSize    to print the value set by -Xss)

 

Execute commands on production environment

ps hH p <pid> | wc -l

The number of threads of the process of the application under normal operation is 1000. Under normal circumstances, the number of threads is 75% of the average. Therefore, it is very likely to reach the limit value during occasional peak periods.

Guess you like

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