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.7 by jsr166, Sat Dec 31 19:25:33 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.BlockingQueue;
16 > import java.util.concurrent.ExecutorService;
17 > import java.util.concurrent.Executors;
18 > import java.util.concurrent.TimeUnit;
19  
20   public final class TimeoutMutexLoops {
21      static final ExecutorService pool = Executors.newCachedThreadPool();
22      static final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
23      static boolean print = false;
24      static final int ITERS = Integer.MAX_VALUE;
25 <    static final long TIMEOUT = 100;
25 >    static final long TIMEOUT = 100;
26  
27      public static void main(String[] args) throws Exception {
28          int maxThreads = 100;
29 <        if (args.length > 0)
29 >        if (args.length > 0)
30              maxThreads = Integer.parseInt(args[0]);
31  
32          print = true;
# Line 51 | Line 53 | public final class TimeoutMutexLoops {
53          }
54  
55          final void test() throws Exception {
56 <            for (int i = 0; i < nthreads; ++i)
56 >            for (int i = 0; i < nthreads; ++i)
57                  pool.execute(this);
58              barrier.await();
59              Thread.sleep(TIMEOUT);
# Line 59 | Line 61 | public final class TimeoutMutexLoops {
61              barrier.await();
62              if (print) {
63                  long time = timer.getTime();
64 <                double secs = (double)(time) / 1000000000.0;
64 >                double secs = (double) time / 1000000000.0;
65                  System.out.println("\t " + secs + "s run time");
66              }
67  
# Line 72 | Line 74 | public final class TimeoutMutexLoops {
74  
75          public final void run() {
76              try {
77 <                barrier.await();
77 >                barrier.await();
78                  int sum = v;
79                  int x = 0;
80                  int n = ITERS;
# Line 92 | Line 94 | public final class TimeoutMutexLoops {
94                  barrier.await();
95                  result += sum;
96              }
97 <            catch (Exception ie) {
98 <                return;
97 >            catch (Exception ie) {
98 >                return;
99              }
100          }
101      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines