4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import java.util.*; |
8 |
< |
import java.util.concurrent.*; |
9 |
< |
import java.util.concurrent.locks.*; |
10 |
< |
import java.util.concurrent.atomic.*; |
7 |
> |
import java.util.ArrayList; |
8 |
> |
import java.util.Queue; |
9 |
> |
import java.util.concurrent.Callable; |
10 |
> |
import java.util.concurrent.CyclicBarrier; |
11 |
> |
import java.util.concurrent.ExecutorService; |
12 |
> |
import java.util.concurrent.Executors; |
13 |
> |
import java.util.concurrent.Future; |
14 |
|
|
15 |
|
public class ConcurrentQueueLoops { |
16 |
|
static final ExecutorService pool = Executors.newCachedThreadPool(); |
24 |
|
public static void main(String[] args) throws Exception { |
25 |
|
int maxStages = 100; |
26 |
|
int work = 1024; |
27 |
< |
Class klass = null; |
27 |
> |
Class<?> klass = null; |
28 |
|
if (args.length > 0) { |
29 |
|
try { |
30 |
|
klass = Class.forName(args[0]); |
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
< |
static void oneRun(Class klass, int n) throws Exception { |
123 |
< |
Queue<Integer> q = (Queue<Integer>) klass.newInstance(); |
122 |
> |
static void oneRun(Class<?> klass, int n) throws Exception { |
123 |
> |
Queue<Integer> q = |
124 |
> |
(Queue<Integer>) klass.getConstructor().newInstance(); |
125 |
|
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); |
126 |
|
CyclicBarrier barrier = new CyclicBarrier(n + 1, timer); |
127 |
|
ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>(n); |