Skip to content

Commit 494db8f

Browse files
authored
Merge pull request #301 from dmlloyd/fix-shutdown-race
Avoid race with shutdownNow (3.4)
2 parents 2fadc13 + 2a070ed commit 494db8f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/org/jboss/threads/EnhancedQueueExecutor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,10 @@ public void shutdown(boolean interrupt) {
956956
// a marker to indicate that termination was requested
957957
for (;;) {
958958
tailNext = tail.getNext();
959-
if (tailNext instanceof TaskNode) {
959+
if (tailNext == tail) {
960+
// we raced with shutdownNow, and now we're in a pickle! re-get tail & retry
961+
tail = getTail();
962+
} else if (tailNext instanceof TaskNode) {
960963
tail = (TaskNode) tailNext;
961964
} else if (tailNext instanceof PoolThreadNode || tailNext == null) {
962965
// remove the entire chain from this point

0 commit comments

Comments
 (0)