package com.competition.score.test;
import java.util.concurrent.CountDownLatch;
public class TestThread {
public static void main(String[] args) {
for (int i = 0;; i++) {
System.out.println("i = " + i);
new Thread(new HoldThread()).start();
}
}
}
class HoldThread extends Thread {
CountDownLatch cdl = new CountDownLatch(1);
public HoldThread() {
this.setDaemon(true);
}
public void run() {
try {
cdl.await();
} catch (InterruptedException e) {
}
}
}
?可用如上程序测试可用的最大线程数。注意:如上程序运行完毕需要重启虚拟机来清除线程占用。
原文:http://pda158.iteye.com/blog/2258075