ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/CancelledFutureLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/CancelledFutureLoops.java (file contents):
Revision 1.2 by dl, Mon May 9 19:33:30 2005 UTC vs.
Revision 1.3 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 6 | Line 6
6  
7   /*
8   * @test
9 < * @summary Checks for responsiveness of futures to cancellation.
9 > * @summary Checks for responsiveness of futures to cancellation.
10   * Runs under
11   * the assumption that ITERS computations require more than TIMEOUT
12   * msecs to complete.
# Line 27 | Line 27 | public final class CancelledFutureLoops
27      static final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
28      static boolean print = false;
29      static final int ITERS = 10000000;
30 <    static final long TIMEOUT = 100;
30 >    static final long TIMEOUT = 100;
31  
32      public static void main(String[] args) throws Exception {
33          int maxThreads = 100;
34 <        if (args.length > 0)
34 >        if (args.length > 0)
35              maxThreads = Integer.parseInt(args[0]);
36  
37          print = true;
# Line 57 | Line 57 | public final class CancelledFutureLoops
57  
58          final void test() throws Exception {
59              Future[] futures = new Future[nthreads];
60 <            for (int i = 0; i < nthreads; ++i)
60 >            for (int i = 0; i < nthreads; ++i)
61                  futures[i] = pool.submit(this);
62  
63              barrier.await();
# Line 67 | Line 67 | public final class CancelledFutureLoops
67                  if (!futures[i].cancel(true))
68                      tooLate = true;
69                  // Unbunch some of the cancels
70 <                if ( (i & 3) == 0)
70 >                if ( (i & 3) == 0)
71                      Thread.sleep(1 + rng.next() % 10);
72              }
73  
# Line 80 | Line 80 | public final class CancelledFutureLoops
80              }
81              else
82                  System.out.print("(cancelled too late) ");
83 <            
83 >
84              long endTime = System.nanoTime();
85              long time = endTime - timer.startTime;
86              if (print) {
# Line 91 | Line 91 | public final class CancelledFutureLoops
91          }
92  
93          public final Object call() throws Exception {
94 <            barrier.await();
94 >            barrier.await();
95              int sum = v;
96              int x = 0;
97              int n = ITERS;
# Line 104 | Line 104 | public final class CancelledFutureLoops
104                      lock.unlock();
105                  }
106                  sum += LoopHelpers.compute2(LoopHelpers.compute2(x));
107 <            }
107 >            }
108              return new Integer(sum);
109          }
110      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines