我正在使用的线程测试的代码如下:
public class ThreadTest {
public static void main(String[] pArgs) throws Exception {
try {
// keep spawning new threads forever
while (true) {
new TestThread().start();
}
}
// when out of memory error is reached, print out the number of
// successful threads spawned and exit
catch ( OutOfMemoryError e ) {
System.out.println(TestThread.CREATE_COUNT);
System.exit(-1);
}
}
static class TestThread extends Thread {
private static int CREATE_COUNT = 0;
public TestThread() {
CREATE_COUNT++;
}
// make the thread wait for eternity after being spawned
public void run() {
try {
sleep(Integer.MAX_VALUE);
}
// even if there is an interruption, dont do anything
catch (InterruptedException e) {
}
}
}
}
发布于 2018-08-15 13:31:38
应该能够运行线程限制来找到最大线程数,并且可以通过编译glibc来调整它
发布于 2018-08-15 14:31:17
用nptl线程将内核更新到更新版本(2.6左右)解决了这个问题
https://stackoverflow.com/questions/-100008794
复制相似问题