运行此代码
for (int i = 0; i < 4000; i++) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
}
}
}).start();
System.out.println(i);
}
结果是
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:658)
at com.codeoverdrive.burnbearburn.Main.main(Main.java:10)
2024 年运行线程之后。使用 JVM 堆和堆栈大小并没有帮助。
sysctl kern.num_threads
返回
kern.num_threads: 10240
OS X Mountain Lion 10.8.4,配备 4GB RAM 的 Macbook Air
有什么建议么?