From b09bf5b1fb0c1dec843d6f5738ecc3da727604af Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 15 Mar 2012 14:31:01 +0100 Subject: [PATCH] Tasks added to OrderedMemoryAwareThreadPoolExecutor may be lost in some cases. See #234 --- .../execution/OrderedMemoryAwareThreadPoolExecutor.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/handler/src/main/java/io/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java b/handler/src/main/java/io/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java index 5434ac5e59..65fd86976f 100644 --- a/handler/src/main/java/io/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java +++ b/handler/src/main/java/io/netty/handler/execution/OrderedMemoryAwareThreadPoolExecutor.java @@ -295,9 +295,12 @@ public class OrderedMemoryAwareThreadPoolExecutor extends @Override public void run() { + boolean acquired = false; + // check if its already running by using CAS. If so just return here. So in the worst case the thread // is executed and do nothing if (isRunning.compareAndSet(false, true)) { + acquired = true; try { Thread thread = Thread.currentThread(); for (;;) { @@ -324,6 +327,10 @@ public class OrderedMemoryAwareThreadPoolExecutor extends // set it back to not running isRunning.set(false); } + + if (acquired && !isRunning.get() && tasks.peek() != null) { + doUnorderedExecute(this); + } } } }