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

Comparing jsr166/src/test/loops/TimeoutMutexLoops.java (file contents):
Revision 1.2 by dl, Mon May 9 19:33:30 2005 UTC vs.
Revision 1.8 by jsr166, Sat Dec 31 19:29:58 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6   /*
7   * @test
# Line 11 | Line 11
11   * decade.
12   */
13  
14 < import java.util.concurrent.*;
15 < import java.util.concurrent.locks.*;
16 < import java.util.*;
14 > import java.util.concurrent.CyclicBarrier;
15 > import java.util.concurrent.ExecutorService;
16 > import java.util.concurrent.Executors;
17 > import java.util.concurrent.TimeUnit;
18  
19   public final class TimeoutMutexLoops {
20      static final ExecutorService pool = Executors.newCachedThreadPool();
21      static final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
22      static boolean print = false;
23      static final int ITERS = Integer.MAX_VALUE;
24 <    static final long TIMEOUT = 100;
24 >    static final long TIMEOUT = 100;
25  
26      public static void main(String[] args) throws Exception {
27          int maxThreads = 100;
28 <        if (args.length > 0)
28 >        if (args.length > 0)
29              maxThreads = Integer.parseInt(args[0]);
30  
31          print = true;
# Line 51 | Line 52 | public final class TimeoutMutexLoops {
52          }
53  
54          final void test() throws Exception {
55 <            for (int i = 0; i < nthreads; ++i)
55 >            for (int i = 0; i < nthreads; ++i)
56                  pool.execute(this);
57              barrier.await();
58              Thread.sleep(TIMEOUT);
# Line 59 | Line 60 | public final class TimeoutMutexLoops {
60              barrier.await();
61              if (print) {
62                  long time = timer.getTime();
63 <                double secs = (double)(time) / 1000000000.0;
63 >                double secs = (double) time / 1000000000.0;
64                  System.out.println("\t " + secs + "s run time");
65              }
66  
# Line 72 | Line 73 | public final class TimeoutMutexLoops {
73  
74          public final void run() {
75              try {
76 <                barrier.await();
76 >                barrier.await();
77                  int sum = v;
78                  int x = 0;
79                  int n = ITERS;
# Line 92 | Line 93 | public final class TimeoutMutexLoops {
93                  barrier.await();
94                  result += sum;
95              }
96 <            catch (Exception ie) {
97 <                return;
96 >            catch (Exception ie) {
97 >                return;
98              }
99          }
100      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines