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.15 by dl, Mon Dec 22 16:25:20 2003 UTC vs.
Revision 1.16 by dl, Tue Dec 23 19:38:09 2003 UTC

# Line 178 | Line 178 | public abstract class AbstractExecutorSe
178          List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size());
179          boolean done = false;
180          try {
181 <            for (Callable<T> t : tasks) {
182 <                FutureTask<T> f = new FutureTask<T>(t);
183 <                futures.add(f);
184 <                execute(f);
185 <            }
181 >            for (Callable<T> t : tasks)
182 >                futures.add(new FutureTask<T>(t));
183 >
184              long lastTime = System.nanoTime();
185 +
186 +            // Interleave time checks and calls to execute in case
187 +            // executor doesn't have any/much parallelism.
188 +            Iterator<Future<T>> it = futures.iterator();
189 +            while (it.hasNext()) {
190 +                execute((Runnable)(it.next()));
191 +                long now = System.nanoTime();
192 +                nanos -= now - lastTime;
193 +                lastTime = now;
194 +                if (nanos <= 0)
195 +                    return futures;
196 +            }
197 +
198              for (Future<T> f : futures) {
199                  if (!f.isDone()) {
200 <                    if (nanos < 0)
200 >                    if (nanos <= 0)
201                          return futures;
202                      try {
203                          f.get(nanos, TimeUnit.NANOSECONDS);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines