JAVA中CountDownLatch的简单示例

java

public static void main(String[] args) throws InterruptedException {

CountDownLatch latch =new CountDownLatch(10);

for (int i = 0; i < 900; i++) {

new Thread(new Runnable() {

@Override

public void run() {

System.out.println(Thread.currentThread().getName() );

try {

Thread.sleep(10000);

} catch (InterruptedException e) {

e.printStackTrace();

} finally {

latch.countDown();

}

}

}).start();

}

System.out.println("等待子线程运行结束");

latch.await();

System.out.println("子线程运行结束");

}

以上是 JAVA中CountDownLatch的简单示例 的全部内容, 来源链接: utcz.com/z/392406.html

回到顶部