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 |
|
import java.util.concurrent.*; |
8 |
|
|
9 |
– |
|
9 |
|
public class TimeoutProducerConsumerLoops { |
10 |
|
static final int NCPUS = Runtime.getRuntime().availableProcessors(); |
11 |
|
static final ExecutorService pool = Executors.newCachedThreadPool(); |
50 |
|
maxPairs = Integer.parseInt(args[0]); |
51 |
|
|
52 |
|
print = true; |
53 |
< |
int k = 1; |
55 |
< |
for (int i = 1; i <= maxPairs;) { |
53 |
> |
for (int k = 1, i = 1; i <= maxPairs;) { |
54 |
|
System.out.println("Pairs:" + i); |
55 |
|
oneTest(i, iters); |
56 |
|
Thread.sleep(100); |
62 |
|
i = k; |
63 |
|
} |
64 |
|
pool.shutdown(); |
65 |
< |
} |
65 |
> |
} |
66 |
|
|
67 |
|
static void oneTest(int n, int iters) throws Exception { |
68 |
|
if (print) |
107 |
|
|
108 |
|
} |
109 |
|
|
110 |
< |
static abstract class Stage implements Runnable { |
110 |
> |
abstract static class Stage implements Runnable { |
111 |
|
final int iters; |
112 |
|
final BlockingQueue<Integer> queue; |
113 |
|
final CyclicBarrier barrier; |