Commit 7d9291e3 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch15] Flipping success check in Atomic BankBalance so it's easier to understand.

parent 94f9fd89
Loading
Loading
Loading
Loading
+3 −4
Changes for src/main/java/ch15/RyanAndMonicaAtomicTest.java: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -56,12 +56,11 @@ class BankAccountWithAtomic {
        Thread.sleep(500);
      } catch (InterruptedException ex) {ex.printStackTrace();}
      System.out.println(name + " woke up.");

      boolean success = balance.compareAndSet(initialBalance, initialBalance - amount);
      if (!success) {
        System.out.println("Sorry " + name + ", try again");
      } else {
      if (success) {
        System.out.println(name + " completes the withdrawal.");
      } else {
        System.out.println("Sorry " + name + ", try again");
      }
    } else {
      System.out.println("Sorry, not enough for " + name);