Fixed issue for DelayTimer, when changing the timer during the callback
This commit is contained in:
parent
357895cc79
commit
0b104291cb
|
@ -23,7 +23,7 @@ class DelayTimer {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final boolean isDaemon;
|
private final boolean isDaemon;
|
||||||
private final Runnable listener;
|
private final Runnable listener;
|
||||||
private Timer timer;
|
private volatile Timer timer;
|
||||||
private long delay;
|
private long delay;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
@ -85,8 +85,19 @@ class DelayTimer {
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
|
// timer can change if the callback calls delay() or cancel()
|
||||||
|
Timer origTimer = DelayTimer.this.timer;
|
||||||
|
|
||||||
DelayTimer.this.listener.run();
|
DelayTimer.this.listener.run();
|
||||||
DelayTimer.this.cancel();
|
|
||||||
|
if (origTimer != null) {
|
||||||
|
origTimer.cancel();
|
||||||
|
origTimer.purge();
|
||||||
|
|
||||||
|
if (origTimer == DelayTimer.this.timer) {
|
||||||
|
DelayTimer.this.timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.timer.schedule(t, delay);
|
this.timer.schedule(t, delay);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user