package com.hzh.corejava.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * Created by huangzehai on 2017/2/20.
 */
class CountDownLatchExample2 { // ...
    private static final int N = 3;

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch doneSignal = new CountDownLatch(N);
        Executor e = Executors.newFixedThreadPool(3);

        for (int i = 0; i < N; ++i) // create and start threads
            e.execute(new WorkerRunnable(doneSignal, i));

        doneSignal.await();           // wait for all to finish
        System.out.println("Done all jobs");
    }
}

class WorkerRunnable implements Runnable {
    private final CountDownLatch doneSignal;
    private final int i;

    WorkerRunnable(CountDownLatch doneSignal, int i) {
        this.doneSignal = doneSignal;
        this.i = i;
    }

    public void run() {
        doWork(i);
        doneSignal.countDown();
    }

    void doWork(int i) {
        System.out.println("Do job for part " + i);
    }
}
@@ -113,16 +113,61 @@
 ecutor;%0A
+import java.util.concurrent.ExecutorService;%0A
 import j
@@ -197,16 +197,16 @@
 cutors;%0A
-
 %0A/**%0A * 
@@ -468,16 +468,23 @@
 Executor
+Service
  e = Exe
@@ -633,24 +633,24 @@
 gnal, i));%0A%0A
-
         done
@@ -701,16 +701,38 @@
  finish%0A
+        e.shutdown();%0A
         

Fix issue of count down latch example2 didn't shutdown