ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/FutureTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/FutureTask.java (file contents):
Revision 1.20 by dl, Mon Dec 22 16:25:20 2003 UTC vs.
Revision 1.21 by dl, Tue Dec 23 19:38:09 2003 UTC

# Line 100 | Line 100 | public class FutureTask<V> implements Fu
100      }
101  
102      public boolean cancel(boolean mayInterruptIfRunning) {
103 +        final ReentrantLock lock = this.lock;
104 +        Thread interruptThread = null;
105          lock.lock();
106          try {
107              Object r = runState;
108              if (r == DONE || r == CANCELLED)
109                  return false;
108            runState = CANCELLED;
109            accessible.signalAll();
110              if (mayInterruptIfRunning && r != null && r instanceof Thread)
111 <                ((Thread)r).interrupt();
111 >                interruptThread = (Thread)r;
112 >            accessible.signalAll();
113 >            runState = CANCELLED;
114          }
115          finally{
116              lock.unlock();
117          }
118 +        if (interruptThread != null)
119 +            interruptThread.interrupt();
120          done();
121          return true;
122      }
# Line 130 | Line 134 | public class FutureTask<V> implements Fu
134       * while waiting
135       */
136      public V get() throws InterruptedException, ExecutionException {
137 +        final ReentrantLock lock = this.lock;
138          lock.lock();
139          try {
140              for (;;) {
# Line 167 | Line 172 | public class FutureTask<V> implements Fu
172      public V get(long timeout, TimeUnit unit)
173          throws InterruptedException, ExecutionException, TimeoutException {
174          long nanos = unit.toNanos(timeout);
175 +        final ReentrantLock lock = this.lock;
176          lock.lock();
177          try {
178              for (;;) {
# Line 205 | Line 211 | public class FutureTask<V> implements Fu
211       * @param v the value
212       */
213      protected void set(V v) {
214 +        final ReentrantLock lock = this.lock;
215          lock.lock();
216          try {
217              if (runState == CANCELLED)
# Line 225 | Line 232 | public class FutureTask<V> implements Fu
232       * @param t the cause of failure.
233       */
234      protected void setException(Throwable t) {
235 +        final ReentrantLock lock = this.lock;
236          lock.lock();
237          try {
238              if (runState == CANCELLED)
# Line 244 | Line 252 | public class FutureTask<V> implements Fu
252       * @return true if successful
253       */
254     private boolean setRunning() {
255 +        final ReentrantLock lock = this.lock;
256          lock.lock();
257          try {
258              if (runState != null)
# Line 263 | Line 272 | public class FutureTask<V> implements Fu
272       * @return true if successful
273       */
274      private boolean reset() {
275 +        final ReentrantLock lock = this.lock;
276          lock.lock();
277          try {
278              if (runState == CANCELLED)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines