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

[Ch15b] More readable output

parent ff0453b3
Loading
Loading
Loading
Loading
+6 −5
Changes for src/main/java/ch15/LotsOfReaders.java: 6 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -11,25 +11,26 @@ public class LotsOfReaders {
    ExecutorService executor = Executors.newFixedThreadPool(4);
    for (int i = 0; i < 5; i++) {
      executor.execute(new Chatty(chatHistory));
      executor.execute(new ChatReader(chatHistory));
      executor.execute(new ChatReader(chatHistory));
      executor.execute(new ChatReader("Reader 1", chatHistory));
      executor.execute(new ChatReader("Reader 2", chatHistory));
    }
    executor.shutdown();
  }

}

class ChatReader implements Runnable {
  private String name;
  private ChatHistory chatHistory;

  public ChatReader(ChatHistory chatHistory) {
  public ChatReader(String name, ChatHistory chatHistory) {
    this.name = name;
    this.chatHistory = chatHistory;
  }

  @Override
  public void run() {
    for (Chat chat : chatHistory.getHistory()) {
      System.out.println(chat);
      System.out.println(name + " read: " + chat);
    }
  }
}