Java-xms256m-xmx1024m-xss256k-jar Doors.jar > Doorlog.txt 2>&1 &
Problem description
The Java program throws the java.lang.OutOfMemoryError:unable to create new native thread as follows:
[Java]View PlainCopy
- Java.lang.OutOfMemoryError:unable to create new native thread
- At Java.lang.Thread.start0 (Native Method)
- At Java.lang.Thread.start (Thread.java:691)
- At Java.util.concurrent.ThreadPoolExecutor.addWorker (Threadpoolexecutor.java:949)
- At Java.util.concurrent.ThreadPoolExecutor.processWorkerExit (Threadpoolexecutor.java:1017)
- At Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1163)
- At Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:615)
- At Java.lang.Thread.run (Thread.java:722)
[Java]View PlainCopy
- caused By:java.lang.OutOfMemoryError
- At Java.util.zip.ZipFile.open (Native Method)
- At Java.util.zip.zipfile.<init> (Zipfile.java:214)
- At Java.util.zip.zipfile.<init> (Zipfile.java:144)
- At Java.util.jar.jarfile.<init> (Jarfile.java:153)
- At Java.util.jar.jarfile.<init> (Jarfile.java:117)
From the JVM level to solve
Reduce the size of the thread stack
The JVM default thread stack size is 1024, so that when threads cause native virtual memory to be exhausted, it is actually sufficient when the size of the thread stack is 128K or 256K, so if we explicitly specify thread Stack is 128K or 256K, specific use-Xss,例如在JVM启动的JVM_OPT中添加如下配置
[Java]View PlainCopy
- -xss128k
Reduce the size of the initial allocation of the heap or PermGen
If the JVM starts with the following configuration in the Jvm_opt
[Java]View PlainCopy
- -xms1303m-xmx1303m-xx:permsize=256m-xx:maxpermsize=256m
We can delete or reduce the configuration of the initialization minimum value, as follows
[Java]View PlainCopy
- -xms256m-xmx1303m-xx:permsize=64m-xx:maxpermsize=256m
[Java]View PlainCopy
- -xmx1303m-xx:maxpermsize=256m
升级JVM到最新的版本
The latest version of the JVM generally does better in memory optimization, and upgrading the JVM to the latest version may alleviate the problem of testing
从操作系统层面去解决
使用64位操作系统
如果使用32位操作系统遇到unable to create new native thread,建议使用64位操作系统
Increase the OS's limit on threads
Set Nofile and Nproc in the Linux operating system, specific edits/etc/security/limits.conf添加如下:
[HTML]View PlainCopy
- Soft Nofile 2048
- Hard Nofile 8192
[HTML]View PlainCopy
- Soft Nproc 2048
- Hard Nproc 8192
If you are using red Hat Enterprise Linux 6, edit/etc/security/limits.d/90-nproc.conf,添加如下配置:
[HTML]View PlainCopy
- # cat/etc/security/limits.d/90-nproc.conf
- * Soft Nproc 1024
- Root Soft Nproc Unlimited
- User-nproc 2048
Java Startup command optimization