Skip to content

Commit

Permalink
Avoid TaskRunner destruction on cancel
Browse files Browse the repository at this point in the history
Drivers may leave the TaskRunner thread's interrupt flag set during the
course of processing, but doing so should not result in the TaskRunner
terminating its own processing loop until the TaskExecutor is closed.

Instead of allowing the interrupt to terminate the current task runner's
loop and re-creating a new runner to replace the interrupted one, we can
clear the interrupt flag after each iteration. Otherwise, TaskRunners
that were interrupted would have to replace themselves and end up
creating unnecessary threads in the cached threadpool executor in the
process.
  • Loading branch information
pettyjamesm committed Feb 3, 2023
1 parent c4a2590 commit 6c4459c
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ public void run()
}
splitFinished(split);
}
finally {
// Clear the interrupted flag on the current thread, driver cancellation may have triggered an interrupt
// without TaskExecutor being shut down
if (Thread.interrupted()) {
if (closed) {
// reset interrupted flag if TaskExecutor was closed, since that interrupt may have been the
// shutdown signal to this TaskRunner thread
Thread.currentThread().interrupt();
}
}
}
}
}
finally {
Expand Down

0 comments on commit 6c4459c

Please sign in to comment.