Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
aloyszhang committed Sep 23, 2020
1 parent 6192b10 commit 9896eb5
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public abstract class TimerTask implements Runnable {

protected final long delayMs;
private TimerTaskEntry timerTaskEntry = null;
private volatile TimerTaskEntry timerTaskEntry = null;

protected TimerTask(long delayMs) {
this.delayMs = delayMs;
Expand All @@ -35,15 +35,18 @@ public synchronized void cancel() {
}

synchronized void setTimerTaskEntry(TimerTaskEntry entry) {
// if this timerTask is already held by an existing timer task entry,
// we will remove such an entry first.
if (null != timerTaskEntry && timerTaskEntry != entry) {
timerTaskEntry.remove();
synchronized (this) {
// if this timerTask is already held by an existing timer task entry,
// we will remove such an entry first.
if (null != timerTaskEntry && timerTaskEntry != entry) {
timerTaskEntry.remove();
}
timerTaskEntry = entry;
}
timerTaskEntry = entry;

}

synchronized TimerTaskEntry getTimerTaskEntry() {
TimerTaskEntry getTimerTaskEntry() {
return timerTaskEntry;
}

Expand Down

0 comments on commit 9896eb5

Please sign in to comment.