Move pendingDeadline.cancel out of synchronized block

This commit is contained in:
Kristofer Karlsson 2021-02-17 14:42:57 +01:00 committed by Eric Anderson
parent e73f31a561
commit 3c4d3d2bb2
1 changed files with 5 additions and 1 deletions

View File

@ -826,18 +826,22 @@ public class Context {
@CanIgnoreReturnValue
public boolean cancel(Throwable cause) {
boolean triggeredCancel = false;
ScheduledFuture<?> localPendingDeadline = null;
synchronized (this) {
if (!cancelled) {
cancelled = true;
if (pendingDeadline != null) {
// If we have a scheduled cancellation pending attempt to cancel it.
pendingDeadline.cancel(false);
localPendingDeadline = pendingDeadline;
pendingDeadline = null;
}
this.cancellationCause = cause;
triggeredCancel = true;
}
}
if (localPendingDeadline != null) {
localPendingDeadline.cancel(false);
}
if (triggeredCancel) {
notifyAndClearListeners();
}