4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import java.util.*; |
8 |
< |
import java.util.concurrent.*; |
9 |
< |
import java.util.concurrent.atomic.*; |
10 |
< |
import java.util.concurrent.locks.*; |
7 |
> |
import java.util.ArrayList; |
8 |
> |
import java.util.Deque; |
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 |
> |
import java.util.concurrent.atomic.AtomicInteger; |
15 |
|
|
16 |
|
public class ConcurrentDequeLoops { |
17 |
|
static final ExecutorService pool = Executors.newCachedThreadPool(); |
22 |
|
int maxStages = 8; |
23 |
|
int items = 1000000; |
24 |
|
|
25 |
< |
Class klass = null; |
25 |
> |
Class<?> klass = null; |
26 |
|
if (args.length > 0) { |
27 |
|
try { |
28 |
|
klass = Class.forName(args[0]); |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
< |
static void oneRun(Class klass, int n, int items) throws Exception { |
124 |
< |
Deque<Integer> q = (Deque<Integer>) klass.newInstance(); |
123 |
> |
static void oneRun(Class<?> klass, int n, int items) throws Exception { |
124 |
> |
Deque<Integer> q = |
125 |
> |
(Deque<Integer>) klass.getConstructor().newInstance(); |
126 |
|
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); |
127 |
|
CyclicBarrier barrier = new CyclicBarrier(n + 1, timer); |
128 |
|
totalItems = new AtomicInteger(n * items); |
145 |
|
System.out.println(LoopHelpers.rightJustify(time / (items * n)) + " ns per item"); |
146 |
|
if (total == 0) // avoid overoptimization |
147 |
|
System.out.println("useless result: " + total); |
143 |
– |
|
148 |
|
} |
149 |
|
} |