Calling cancel on a Future returned by a TaskScheduler works reliably now

Issue: SPR-9821
This commit is contained in:
Juergen Hoeller 2012-09-25 12:06:43 +02:00
parent ef9d35c473
commit e0bec678da
1 changed files with 24 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,9 +49,9 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc
private final ScheduledExecutorService executor;
private volatile ScheduledFuture currentFuture;
private ScheduledFuture currentFuture;
private volatile Date scheduledExecutionTime;
private Date scheduledExecutionTime;
private final Object triggerContextMonitor = new Object();
@ -82,35 +82,47 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc
Date completionTime = new Date();
synchronized (this.triggerContextMonitor) {
this.triggerContext.update(this.scheduledExecutionTime, actualExecutionTime, completionTime);
}
if (!this.currentFuture.isCancelled()) {
schedule();
if (!this.currentFuture.isCancelled()) {
schedule();
}
}
}
public boolean cancel(boolean mayInterruptIfRunning) {
return this.currentFuture.cancel(mayInterruptIfRunning);
synchronized (this.triggerContextMonitor) {
return this.currentFuture.cancel(mayInterruptIfRunning);
}
}
public boolean isCancelled() {
return this.currentFuture.isCancelled();
synchronized (this.triggerContextMonitor) {
return this.currentFuture.isCancelled();
}
}
public boolean isDone() {
return this.currentFuture.isDone();
synchronized (this.triggerContextMonitor) {
return this.currentFuture.isDone();
}
}
public Object get() throws InterruptedException, ExecutionException {
return this.currentFuture.get();
synchronized (this.triggerContextMonitor) {
return this.currentFuture.get();
}
}
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return this.currentFuture.get(timeout, unit);
synchronized (this.triggerContextMonitor) {
return this.currentFuture.get(timeout, unit);
}
}
public long getDelay(TimeUnit unit) {
return this.currentFuture.getDelay(unit);
synchronized (this.triggerContextMonitor) {
return this.currentFuture.getDelay(unit);
}
}
public int compareTo(Delayed other) {