|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2012 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -49,9 +49,9 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc
|
49 | 49 |
|
50 | 50 | private final ScheduledExecutorService executor;
|
51 | 51 |
|
52 |
| - private volatile ScheduledFuture currentFuture; |
| 52 | + private ScheduledFuture currentFuture; |
53 | 53 |
|
54 |
| - private volatile Date scheduledExecutionTime; |
| 54 | + private Date scheduledExecutionTime; |
55 | 55 |
|
56 | 56 | private final Object triggerContextMonitor = new Object();
|
57 | 57 |
|
@@ -82,35 +82,47 @@ public void run() {
|
82 | 82 | Date completionTime = new Date();
|
83 | 83 | synchronized (this.triggerContextMonitor) {
|
84 | 84 | this.triggerContext.update(this.scheduledExecutionTime, actualExecutionTime, completionTime);
|
85 |
| - } |
86 |
| - if (!this.currentFuture.isCancelled()) { |
87 |
| - schedule(); |
| 85 | + if (!this.currentFuture.isCancelled()) { |
| 86 | + schedule(); |
| 87 | + } |
88 | 88 | }
|
89 | 89 | }
|
90 | 90 |
|
91 | 91 |
|
92 | 92 | public boolean cancel(boolean mayInterruptIfRunning) {
|
93 |
| - return this.currentFuture.cancel(mayInterruptIfRunning); |
| 93 | + synchronized (this.triggerContextMonitor) { |
| 94 | + return this.currentFuture.cancel(mayInterruptIfRunning); |
| 95 | + } |
94 | 96 | }
|
95 | 97 |
|
96 | 98 | public boolean isCancelled() {
|
97 |
| - return this.currentFuture.isCancelled(); |
| 99 | + synchronized (this.triggerContextMonitor) { |
| 100 | + return this.currentFuture.isCancelled(); |
| 101 | + } |
98 | 102 | }
|
99 | 103 |
|
100 | 104 | public boolean isDone() {
|
101 |
| - return this.currentFuture.isDone(); |
| 105 | + synchronized (this.triggerContextMonitor) { |
| 106 | + return this.currentFuture.isDone(); |
| 107 | + } |
102 | 108 | }
|
103 | 109 |
|
104 | 110 | public Object get() throws InterruptedException, ExecutionException {
|
105 |
| - return this.currentFuture.get(); |
| 111 | + synchronized (this.triggerContextMonitor) { |
| 112 | + return this.currentFuture.get(); |
| 113 | + } |
106 | 114 | }
|
107 | 115 |
|
108 | 116 | public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
109 |
| - return this.currentFuture.get(timeout, unit); |
| 117 | + synchronized (this.triggerContextMonitor) { |
| 118 | + return this.currentFuture.get(timeout, unit); |
| 119 | + } |
110 | 120 | }
|
111 | 121 |
|
112 | 122 | public long getDelay(TimeUnit unit) {
|
113 |
| - return this.currentFuture.getDelay(unit); |
| 123 | + synchronized (this.triggerContextMonitor) { |
| 124 | + return this.currentFuture.getDelay(unit); |
| 125 | + } |
114 | 126 | }
|
115 | 127 |
|
116 | 128 | public int compareTo(Delayed other) {
|
|
0 commit comments