Don't expose cleaned-up tasks as pending in PrioritizedEsThreadPoolExecutor (#24237)
Changes in #24102 exposed the following oddity: PrioritizedEsThreadPoolExecutor.getPending() can return Pending entries where pending.task == null. This can happen for example when tasks are added to the pending list while they are in the clean up phase, i.e. TieBreakingPrioritizedRunnable#runAndClean has run already, but afterExecute has not removed the task yet. Instead of safeguarding consumers of the API (as was done before #24102) this changes the executor to not count these tasks as pending at all.
This commit is contained in:
parent
3c7c4bc824
commit
c2deb1c81d
|
@ -91,7 +91,13 @@ public class PrioritizedEsThreadPoolExecutor extends EsThreadPoolExecutor {
|
|||
for (Runnable runnable : runnables) {
|
||||
if (runnable instanceof TieBreakingPrioritizedRunnable) {
|
||||
TieBreakingPrioritizedRunnable t = (TieBreakingPrioritizedRunnable) runnable;
|
||||
pending.add(new Pending(unwrap(t.runnable), t.priority(), t.insertionOrder, executing));
|
||||
Runnable innerRunnable = t.runnable;
|
||||
if (innerRunnable != null) {
|
||||
/** innerRunnable can be null if task is finished but not removed from executor yet,
|
||||
* see {@link TieBreakingPrioritizedRunnable#run} and {@link TieBreakingPrioritizedRunnable#runAndClean}
|
||||
*/
|
||||
pending.add(new Pending(unwrap(innerRunnable), t.priority(), t.insertionOrder, executing));
|
||||
}
|
||||
} else if (runnable instanceof PrioritizedFutureTask) {
|
||||
PrioritizedFutureTask t = (PrioritizedFutureTask) runnable;
|
||||
Object task = t.task;
|
||||
|
|
Loading…
Reference in New Issue