Commit 04931438 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch15] Simplistic example for the book

parent 6f5a1c5f
Loading
Loading
Loading
Loading
+12 −2
Changes for src/main/java/ch15/ClosingTime.java: 12 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -7,8 +7,18 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;

public class ClosingTime {
  public static void main(String[] args) throws InterruptedException {
    fullShutdown();
  public static void main(String[] args) {
    ExecutorService threadPool = Executors.newFixedThreadPool(2);
    threadPool.execute(new LongJob("Long Job 1"));
    threadPool.execute(new ShortJob("Short Job"));
    threadPool.shutdown();

    try {
      System.out.println("Finished? " + threadPool.awaitTermination(4, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    threadPool.shutdownNow();
  }

  static void fullShutdown() throws InterruptedException {