JAVA中CountDownLatch的简单示例

 

 

 

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的简单示例

上一篇:DayOfWeek


下一篇:不适定问题的正则化求解