Tasks added to OrderedMemoryAwareThreadPoolExecutor may be lost in some

cases. See #234
This commit is contained in:
Norman Maurer 2012-03-15 14:31:01 +01:00
parent cb931bfb92
commit b09bf5b1fb

View File

@ -295,9 +295,12 @@ public class OrderedMemoryAwareThreadPoolExecutor extends
@Override @Override
public void run() { 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 // 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 // is executed and do nothing
if (isRunning.compareAndSet(false, true)) { if (isRunning.compareAndSet(false, true)) {
acquired = true;
try { try {
Thread thread = Thread.currentThread(); Thread thread = Thread.currentThread();
for (;;) { for (;;) {
@ -324,6 +327,10 @@ public class OrderedMemoryAwareThreadPoolExecutor extends
// set it back to not running // set it back to not running
isRunning.set(false); isRunning.set(false);
} }
if (acquired && !isRunning.get() && tasks.peek() != null) {
doUnorderedExecute(this);
}
} }
} }
} }