package com.sinoservices.chainwork.srm.tender.manager.impl;
/*
高并发请求服务器时,经常出现如下异常:java.lang.OutOfMemoryError:unable to create new native thread
准确地讲:native thread异常与平台有关
导致原因
1、你的应用创建了太多线程,一个应用进程创建多个线程,超过系统承载极限
2.你的服务器并不允许你的应用程序创建这么多线程,Linux系统默认允许单个进程能创建的线程数是1024个
你的应用创建线程超过了这个数量,就会报:java.lang.OutOfMemoryError:unable to create native thread
解决办法:
1.想办法降低你应用程序创建的线程数量,分析应用是否真的需要创建这么多线程,如果不是改代码,将线程数降到最低。
2.对于有的应用确实需要创建很多线程,远超过Linux系统默认的1024的限制,可以通过修改Linux服务器配置,扩大Linux默认限制
*/
import javax.persistence.criteria.CriteriaBuilder;
import java.util.concurrent.TimeUnit;
public class UnableCreateNewThreadDemo {
public static void main(String[] args) {
for (int i = 1; ; i++) {
System.out.println("***************" + i);
new Thread(()->{
try {
TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
},""+i).start();
}
}
}