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

[Ch15b] Fewer iterations needed to provoke the problem

parent 80e3a58b
Loading
Loading
Loading
Loading
+2 −4
Changes for src/main/java/ch15/ryanmonica/RyanAndMonicaStatementTest.java: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ public class RyanAndMonicaStatementTest {
  public static void main(String[] args) throws InterruptedException {
    BankAccountStatement account = new BankAccountStatement();
    ExecutorService executor = Executors.newCachedThreadPool();
    executor.execute(new RyanAndMonicaStatementJob("Ryan", account, 5));
    executor.execute(new RyanAndMonicaStatementJob("Ryan", account, 20));
    executor.execute(new StatementReaderAccountant("Monica", account));
    executor.execute(new StatementReaderAccountant("Accountant", account));
    executor.execute(new StatementReaderAccountant("Bank Manager", account));
@@ -31,7 +31,7 @@ class RyanAndMonicaStatementJob implements Runnable {
  }

  public void run() {
    for (int i = 0; i < 20; i++) {
    for (int i = 0; i < 5; i++) {
      goShopping(amountToSpend);
    }
  }
@@ -58,14 +58,12 @@ class StatementReaderAccountant implements Runnable {

  @Override
  public void run() {
    for (int i = 0; i < 10; i++) {
    List<Transaction> statement = account.getStatement();
    for (Transaction transaction : statement) {
      System.out.println(name + " read " + transaction);
    }
  }
}
}

class BankAccountStatement {
  private final List<Transaction> statement = new CopyOnWriteArrayList<>();