Java Threadpool
JDK提供了ExecutorService以提供线程池的应用,今天测试了一下线程池的使用,受益匪浅。
不使用线程池
void normalThread(){
final CountDownLatch lock = new CountDownLatch(testCount);
for(int i = 0; i < testCount; i++){
final int item = i;
Thread t = new Thread(new Runnable(){
@Override
public void run() {
handle(item);
lock.countDown();
}
});
t.start();
}
try {
lock.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}