@@ -86,7 +86,7 @@ public static synchronized void execute(Task task) {
8686 Future <?> future = null ;
8787 if (task .serial == null || !hasSerialRunning (task .serial )) {
8888 task .executionAsked = true ;
89- future = directExecute (task , task .delay );
89+ future = directExecute (task , task .remainingDelay );
9090 }
9191 if (task .id != null || task .serial != null ) {
9292 /* keep task */
@@ -246,7 +246,7 @@ private static Task take(String serial) {
246246 public static abstract class Task implements Runnable {
247247
248248 private String id ;
249- private int delay ;
249+ private int remainingDelay ;
250250 private long targetTimeMillis ; /* since epoch */
251251 private String serial ;
252252 private boolean executionAsked ;
@@ -257,7 +257,7 @@ public Task(String id, int delay, String serial) {
257257 this .id = id ;
258258 }
259259 if (delay > 0 ) {
260- this . delay = delay ;
260+ remainingDelay = delay ;
261261 targetTimeMillis = System .currentTimeMillis () + delay ;
262262 }
263263 if (!"" .equals (serial )) {
@@ -289,9 +289,9 @@ private void postExecute() {
289289 if (serial != null ) {
290290 Task next = take (serial );
291291 if (next != null ) {
292- if (next .delay != 0 ) {
293- /* compute remaining delay */
294- next .delay = Math .max (0 , (int ) (targetTimeMillis - System .currentTimeMillis ()));
292+ if (next .remainingDelay != 0 ) {
293+ /* the delay may not have elapsed yet */
294+ next .remainingDelay = Math .max (0 , (int ) (targetTimeMillis - System .currentTimeMillis ()));
295295 }
296296 /* a task having the same serial was queued, execute it */
297297 BackgroundExecutor .execute (next );
0 commit comments