From a179863adbb31a8153b3cd077fd7a77aee81333d Mon Sep 17 00:00:00 2001 From: Bruce Eckel Date: Sat, 14 Jan 2017 15:49:57 -0800 Subject: [PATCH] Doesn't need CopyOnWrite --- lowlevel/DelayQueueDemo.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lowlevel/DelayQueueDemo.java b/lowlevel/DelayQueueDemo.java index e2fbb295..8913d1f2 100644 --- a/lowlevel/DelayQueueDemo.java +++ b/lowlevel/DelayQueueDemo.java @@ -13,7 +13,7 @@ class DelayedTask implements Runnable, Delayed { private final int delta; private final long trigger; protected static List sequence = - new CopyOnWriteArrayList<>(); + new ArrayList<>(); public DelayedTask(int delayInMilliseconds) { delta = delayInMilliseconds; trigger = System.nanoTime() + @@ -49,7 +49,7 @@ class DelayedTask implements Runnable, Delayed { @Override public void run() { sequence.forEach(dt -> - System.out.println(dt.summary() + " ")); + System.out.println(dt.summary())); } } } @@ -58,8 +58,7 @@ public class DelayQueueDemo { public static void main(String[] args) throws Exception { DelayQueue tasks = - Stream.concat( - // Tasks with random delays: + Stream.concat( // Random delays: new Random(47).ints(20, 0, 4000) .mapToObj(DelayedTask::new), // Add the summarizing task: