43 |
|
import java.util.Spliterator; |
44 |
|
import java.util.Vector; |
45 |
|
import java.util.concurrent.ArrayBlockingQueue; |
46 |
+ |
import java.util.concurrent.BlockingQueue; |
47 |
|
import java.util.concurrent.ConcurrentLinkedDeque; |
48 |
|
import java.util.concurrent.ConcurrentLinkedQueue; |
49 |
|
import java.util.concurrent.CountDownLatch; |
264 |
|
Deque<Integer> deque = (Deque<Integer>) x; |
265 |
|
jobs.addAll(dequeJobs(klazz, () -> deque, al)); |
266 |
|
} |
267 |
+ |
if (x instanceof BlockingQueue) { |
268 |
+ |
BlockingQueue<Integer> q = (BlockingQueue<Integer>) x; |
269 |
+ |
jobs.addAll(blockingQueueJobs(klazz, () -> q, al)); |
270 |
+ |
} |
271 |
|
if (x instanceof List) { |
272 |
|
List<Integer> list = (List<Integer>) x; |
273 |
|
jobs.addAll( |
375 |
|
} |
376 |
|
check.sum(sum[0]);}}}); |
377 |
|
} |
378 |
+ |
|
379 |
+ |
List<Job> blockingQueueJobs( |
380 |
+ |
String description, |
381 |
+ |
Supplier<BlockingQueue<Integer>> supplier, |
382 |
+ |
ArrayList<Integer> al) { |
383 |
+ |
return List.of( |
384 |
+ |
new Job(description + " drainTo(sink)") { |
385 |
+ |
public void work() throws Throwable { |
386 |
+ |
BlockingQueue<Integer> x = supplier.get(); |
387 |
+ |
ArrayList<Integer> sink = new ArrayList<>(); |
388 |
+ |
int[] sum = new int[1]; |
389 |
+ |
for (int i = 0; i < iterations; i++) { |
390 |
+ |
sum[0] = 0; |
391 |
+ |
sink.clear(); |
392 |
+ |
x.addAll(al); |
393 |
+ |
x.drainTo(sink); |
394 |
+ |
sink.forEach(e -> sum[0] += e); |
395 |
+ |
check.sum(sum[0]);}}}, |
396 |
+ |
new Job(description + " drainTo(sink, n)") { |
397 |
+ |
public void work() throws Throwable { |
398 |
+ |
BlockingQueue<Integer> x = supplier.get(); |
399 |
+ |
ArrayList<Integer> sink = new ArrayList<>(); |
400 |
+ |
int[] sum = new int[1]; |
401 |
+ |
for (int i = 0; i < iterations; i++) { |
402 |
+ |
sum[0] = 0; |
403 |
+ |
sink.clear(); |
404 |
+ |
x.addAll(al); |
405 |
+ |
x.drainTo(sink, al.size()); |
406 |
+ |
sink.forEach(e -> sum[0] += e); |
407 |
+ |
check.sum(sum[0]);}}}); |
408 |
+ |
} |
409 |
|
} |