Commit 75c79cd4 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch15] Code magnets - maybe this can help me show futures? Right now it shows...

[Ch15] Code magnets - maybe this can help me show futures? Right now it shows how things aren't updated!
parent 076cd064
Loading
Loading
Loading
Loading
+6 −3
Changes for src/main/java/ch15/TestThreads.java: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
package ch15;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestThreads {
  public static void main(String[] args) {
  public static void main(String[] args) throws InterruptedException, ExecutionException {
    ExecutorService pool = Executors.newFixedThreadPool(2);
    pool.execute(() -> {
    Future<?> future1 = pool.submit(() -> {
      Accum a = Accum.getInstance();
      for (int i = 0; i < 98; i++) {
        a.updateCounter(1000);
      }
    });
    pool.execute(() -> {
    System.out.println(future1.isDone());
    Future<?> future2 = pool.submit(() -> {
      Accum a = Accum.getInstance();
      for (int i = 0; i < 99; i++) {
        a.updateCounter(1);