1 |
|
/* |
2 |
< |
* Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. |
2 |
> |
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
28 |
|
* @author Martin Buchholz |
29 |
|
*/ |
30 |
|
|
31 |
< |
import static java.util.Collections.*; |
32 |
< |
import java.util.*; |
33 |
< |
import java.util.concurrent.*; |
31 |
> |
import java.util.ArrayDeque; |
32 |
> |
import java.util.ArrayList; |
33 |
> |
import java.util.Collection; |
34 |
> |
import java.util.Collections; |
35 |
> |
import java.util.Comparator; |
36 |
> |
import java.util.Deque; |
37 |
> |
import java.util.HashMap; |
38 |
> |
import java.util.HashSet; |
39 |
> |
import java.util.Hashtable; |
40 |
> |
import java.util.LinkedList; |
41 |
> |
import java.util.List; |
42 |
> |
import java.util.Map; |
43 |
> |
import java.util.Queue; |
44 |
> |
import java.util.Set; |
45 |
> |
import java.util.TreeMap; |
46 |
> |
import java.util.TreeSet; |
47 |
> |
import java.util.Vector; |
48 |
> |
import java.util.concurrent.ArrayBlockingQueue; |
49 |
> |
import java.util.concurrent.ConcurrentHashMap; |
50 |
> |
import java.util.concurrent.ConcurrentLinkedDeque; |
51 |
> |
import java.util.concurrent.ConcurrentLinkedQueue; |
52 |
> |
import java.util.concurrent.ConcurrentSkipListMap; |
53 |
> |
import java.util.concurrent.ConcurrentSkipListSet; |
54 |
> |
import java.util.concurrent.CopyOnWriteArrayList; |
55 |
> |
import java.util.concurrent.CopyOnWriteArraySet; |
56 |
> |
import java.util.concurrent.LinkedBlockingDeque; |
57 |
> |
import java.util.concurrent.LinkedBlockingQueue; |
58 |
> |
import java.util.concurrent.LinkedTransferQueue; |
59 |
> |
|
60 |
> |
import static java.util.Collections.asLifoQueue; |
61 |
> |
import static java.util.Collections.checkedList; |
62 |
> |
import static java.util.Collections.checkedMap; |
63 |
> |
import static java.util.Collections.checkedSet; |
64 |
> |
import static java.util.Collections.newSetFromMap; |
65 |
> |
import static java.util.Collections.synchronizedList; |
66 |
> |
import static java.util.Collections.synchronizedMap; |
67 |
> |
import static java.util.Collections.synchronizedSet; |
68 |
> |
import static java.util.Collections.unmodifiableList; |
69 |
> |
import static java.util.Collections.unmodifiableMap; |
70 |
> |
import static java.util.Collections.unmodifiableSet; |
71 |
|
|
72 |
|
public class RacingCollections { |
73 |
|
/** |
195 |
|
quittingTime = System.nanoTime() + workTimeMillis * 1024 * 1024; |
196 |
|
} |
197 |
|
boolean keepGoing() { |
198 |
< |
return (i++ % 128 != 0) || (System.nanoTime() < quittingTime); |
198 |
> |
return (i++ % 128 != 0) || (System.nanoTime() - quittingTime < 0); |
199 |
|
} |
200 |
|
} |
201 |
|
|
221 |
|
} |
222 |
|
|
223 |
|
private static List<Map<Integer, Boolean>> newConcurrentMaps() { |
224 |
< |
List<Map<Integer, Boolean>> list = |
188 |
< |
new ArrayList<Map<Integer, Boolean>>(); |
224 |
> |
List<Map<Integer, Boolean>> list = new ArrayList<>(); |
225 |
|
list.add(new ConcurrentHashMap<Integer, Boolean>()); |
226 |
|
list.add(new ConcurrentSkipListMap<Integer, Boolean>()); |
227 |
|
return list; |
232 |
|
list.add(new Hashtable<Integer, Boolean>()); |
233 |
|
list.add(new HashMap<Integer, Boolean>()); |
234 |
|
list.add(new TreeMap<Integer, Boolean>()); |
235 |
< |
Comparator<Integer> cmp = new Comparator<Integer>() { |
235 |
> |
Comparator<Integer> cmp = new Comparator<>() { |
236 |
|
public int compare(Integer x, Integer y) { |
237 |
|
return x - y; |
238 |
|
}}; |
241 |
|
} |
242 |
|
|
243 |
|
private static List<Set<Integer>> newConcurrentSets() { |
244 |
< |
List<Set<Integer>> list = new ArrayList<Set<Integer>>(); |
244 |
> |
List<Set<Integer>> list = new ArrayList<>(); |
245 |
|
list.add(new ConcurrentSkipListSet<Integer>()); |
246 |
|
list.add(new CopyOnWriteArraySet<Integer>()); |
247 |
|
return list; |
256 |
|
} |
257 |
|
|
258 |
|
private static List<List<Integer>> newConcurrentLists() { |
259 |
< |
List<List<Integer>> list = new ArrayList<List<Integer>>(); |
259 |
> |
List<List<Integer>> list = new ArrayList<>(); |
260 |
|
list.add(new CopyOnWriteArrayList<Integer>()); |
261 |
|
return list; |
262 |
|
} |
269 |
|
} |
270 |
|
|
271 |
|
private static List<Queue<Integer>> newConcurrentQueues() { |
272 |
< |
List<Queue<Integer>> list = |
273 |
< |
new ArrayList<Queue<Integer>>(newConcurrentDeques()); |
272 |
> |
List<Queue<Integer>> list = new ArrayList<>(newConcurrentDeques()); |
273 |
> |
list.add(new ArrayBlockingQueue<Integer>(10)); |
274 |
|
list.add(new LinkedBlockingQueue<Integer>(10)); |
275 |
|
list.add(new LinkedTransferQueue<Integer>()); |
276 |
|
list.add(new ConcurrentLinkedQueue<Integer>()); |
278 |
|
} |
279 |
|
|
280 |
|
private static List<Queue<Integer>> newQueues() { |
281 |
< |
List<Queue<Integer>> list = |
246 |
< |
new ArrayList<Queue<Integer>>(newDeques()); |
281 |
> |
List<Queue<Integer>> list = new ArrayList<>(newDeques()); |
282 |
|
list.add(new LinkedBlockingQueue<Integer>(10)); |
283 |
|
return list; |
284 |
|
} |
285 |
|
|
286 |
|
private static List<Deque<Integer>> newConcurrentDeques() { |
287 |
< |
List<Deque<Integer>> list = new ArrayList<Deque<Integer>>(); |
287 |
> |
List<Deque<Integer>> list = new ArrayList<>(); |
288 |
|
list.add(new LinkedBlockingDeque<Integer>(10)); |
289 |
|
list.add(new ConcurrentLinkedDeque<Integer>()); |
290 |
|
return list; |