From e415de44c64775dd537bab59c89a913f132360b3 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 31 Jul 2014 08:58:19 +1000 Subject: [PATCH] Eat what you kill strategy avoids double dispatch --- .../org/eclipse/jetty/util/thread/ExecutionStrategy.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java index 994b1db8205..1159b93237b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutionStrategy.java @@ -59,7 +59,6 @@ public abstract class ExecutionStrategy implements Runnable _executor=executor; } - /* ------------------------------------------------------------ */ /** Simple iterative strategy. * Iterate over production until complete and execute each task. @@ -113,6 +112,7 @@ public abstract class ExecutionStrategy implements Runnable { private final AtomicInteger _threads = new AtomicInteger(0); private final AtomicReference _producing = new AtomicReference(Boolean.FALSE); + private volatile boolean _dispatched; public EatWhatYouKill(Producer producer, Executor executor) { @@ -121,6 +121,7 @@ public abstract class ExecutionStrategy implements Runnable public void run() { + _dispatched=false; // count the dispatched threads _threads.incrementAndGet(); try @@ -146,9 +147,12 @@ public abstract class ExecutionStrategy implements Runnable } // then we may need another thread to keep producing - if (!complete) + if (!complete && !_dispatched) + { // Dispatch a thread to continue producing + _dispatched=true; _executor.execute(this); + } // If there is a task, if (task!=null)