【发布时间】:2019-01-14 13:05:59
【问题描述】:
我在申请中遇到了以下问题 java.lang.OutOfMemoryError: 无法创建新的本地线程
我的开发环境是windows 7 64bit,部署环境是linux 64bit。我无法在本地开发环境中重现该问题。我得到了以下代码,当我在 linux 服务器中运行时,它在创建线程 3993 时给了我同样的错误。 ulimit -u 给出了 4096 的计数。所以我确信在这个阈值附近的某个地方不允许为进程/应用程序/用户创建新线程。
但是我无法在我的 Windows 开发环境中重现该问题。我很好奇什么代码实际上会给我windows中的线程阈值
public class ThreadLimitChecker
{
public static void main(String[] args)
{
System.out.println("Hello World");
int count = 0;
while (true)
{
count++;
new Thread(new Runnable()
{
public void run()
{
try
{
Thread.sleep(10000000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
System.out.println("Thread #:" + count);
}
}
}
期望发生异常的线程号
【问题讨论】:
-
this question on superuser 表明windows7中没有这样的限制(在资源耗尽之前)
-
对于Linux,有这个相关的问题:stackoverflow.com/questions/344203/…
-
this question on SO 也与之相关,我想您可能想查看this answer first。
标签: java multithreading