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

Comparing jsr166/src/main/java/util/concurrent/AbstractExecutorService.java (file contents):
Revision 1.36 by jsr166, Mon Dec 19 02:53:25 2011 UTC vs.
Revision 1.37 by jsr166, Mon Dec 19 19:58:00 2011 UTC

# Line 129 | Line 129 | public abstract class AbstractExecutorSe
129              // Record exceptions so that if we fail to obtain any
130              // result, we can throw the last exception we got.
131              ExecutionException ee = null;
132 <            long lastTime = timed ? System.nanoTime() : 0;
132 >            final long deadline = timed ? System.nanoTime() + nanos : 0L;
133              Iterator<? extends Callable<T>> it = tasks.iterator();
134  
135              // Start one task for sure; the rest incrementally
# Line 151 | Line 151 | public abstract class AbstractExecutorSe
151                          f = ecs.poll(nanos, TimeUnit.NANOSECONDS);
152                          if (f == null)
153                              throw new TimeoutException();
154 <                        long now = System.nanoTime();
155 <                        nanos -= now - lastTime;
156 <                        lastTime = now;
154 >                        nanos = deadline - System.nanoTime();
155                      }
156                      else
157                          f = ecs.take();
# Line 238 | Line 236 | public abstract class AbstractExecutorSe
236              for (Callable<T> t : tasks)
237                  futures.add(newTaskFor(t));
238  
239 <            long lastTime = System.nanoTime();
239 >            final long deadline = System.nanoTime() + nanos;
240  
241              // Interleave time checks and calls to execute in case
242              // executor doesn't have any/much parallelism.
243              Iterator<Future<T>> it = futures.iterator();
244              while (it.hasNext()) {
245                  execute((Runnable)(it.next()));
246 <                long now = System.nanoTime();
247 <                nanos -= now - lastTime;
250 <                lastTime = now;
251 <                if (nanos <= 0)
246 >                nanos = deadline - System.nanoTime();
247 >                if (nanos <= 0L)
248                      return futures;
249              }
250  
251              for (Future<T> f : futures) {
252                  if (!f.isDone()) {
253 <                    if (nanos <= 0)
253 >                    if (nanos <= 0L)
254                          return futures;
255                      try {
256                          f.get(nanos, TimeUnit.NANOSECONDS);
# Line 263 | Line 259 | public abstract class AbstractExecutorSe
259                      } catch (TimeoutException toe) {
260                          return futures;
261                      }
262 <                    long now = System.nanoTime();
267 <                    nanos -= now - lastTime;
268 <                    lastTime = now;
262 >                    nanos = deadline - System.nanoTime();
263                  }
264              }
265              done = true;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines