8171886: Miscellaneous changes imported from jsr166 CVS 2017-02

Reviewed-by: martin, psandoz
This commit is contained in:
Doug Lea 2017-02-03 13:24:59 -08:00
parent 7f519be836
commit 030a779128
98 changed files with 536 additions and 540 deletions

View File

@ -734,12 +734,12 @@ public class PriorityQueue<E> extends AbstractQueue<E>
@SuppressWarnings("unchecked")
private void heapify() {
final Object[] es = queue;
final int half = (size >>> 1) - 1;
int i = (size >>> 1) - 1;
if (comparator == null)
for (int i = half; i >= 0; i--)
for (; i >= 0; i--)
siftDownComparable(i, (E) es[i]);
else
for (int i = half; i >= 0; i--)
for (; i >= 0; i--)
siftDownUsingComparator(i, (E) es[i]);
}

View File

@ -72,9 +72,8 @@ import java.util.function.Predicate;
* generally decreases throughput but reduces variability and avoids
* starvation.
*
* <p>This class and its iterator implement all of the
* <em>optional</em> methods of the {@link Collection} and {@link
* Iterator} interfaces.
* <p>This class and its iterator implement all of the <em>optional</em>
* methods of the {@link Collection} and {@link Iterator} interfaces.
*
* <p>This class is a member of the
* <a href="{@docRoot}/../technotes/guides/collections/index.html">

View File

@ -72,12 +72,12 @@ import java.util.Spliterator;
* asynchronous nature of these sets, determining the current number
* of elements requires a traversal of the elements, and so may report
* inaccurate results if this collection is modified during traversal.
* Additionally, the bulk operations {@code addAll},
* {@code removeAll}, {@code retainAll}, {@code containsAll},
* {@code equals}, and {@code toArray} are <em>not</em> guaranteed
* to be performed atomically. For example, an iterator operating
* concurrently with an {@code addAll} operation might view only some
* of the added elements.
*
* <p>Bulk operations that add, remove, or examine multiple elements,
* such as {@link #addAll}, {@link #removeIf} or {@link #forEach},
* are <em>not</em> guaranteed to be performed atomically.
* For example, a {@code forEach} traversal concurrent with an {@code
* addAll} operation might observe only some of the added elements.
*
* <p>This class and its iterators implement all of the
* <em>optional</em> methods of the {@link Set} and {@link Iterator}

View File

@ -797,7 +797,7 @@ public class CopyOnWriteArrayList<E>
* @throws NullPointerException {@inheritDoc}
*/
public void forEach(Consumer<? super E> action) {
if (action == null) throw new NullPointerException();
Objects.requireNonNull(action);
for (Object x : getArray()) {
@SuppressWarnings("unchecked") E e = (E) x;
action.accept(e);
@ -808,7 +808,7 @@ public class CopyOnWriteArrayList<E>
* @throws NullPointerException {@inheritDoc}
*/
public boolean removeIf(Predicate<? super E> filter) {
if (filter == null) throw new NullPointerException();
Objects.requireNonNull(filter);
return bulkRemove(filter);
}
@ -865,7 +865,7 @@ public class CopyOnWriteArrayList<E>
}
public void replaceAll(UnaryOperator<E> operator) {
if (operator == null) throw new NullPointerException();
Objects.requireNonNull(operator);
synchronized (lock) {
replaceAll(operator, 0, getArray().length);
}
@ -1329,7 +1329,7 @@ public class CopyOnWriteArrayList<E>
}
public void forEach(Consumer<? super E> action) {
if (action == null) throw new NullPointerException();
Objects.requireNonNull(action);
int i, end; final Object[] es;
synchronized (l.lock) {
es = getArrayChecked();
@ -1341,7 +1341,7 @@ public class CopyOnWriteArrayList<E>
}
public void replaceAll(UnaryOperator<E> operator) {
if (operator == null) throw new NullPointerException();
Objects.requireNonNull(operator);
synchronized (l.lock) {
checkForComodification();
l.replaceAll(operator, offset, offset + size);

View File

@ -41,6 +41,7 @@ import java.util.AbstractQueue;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@ -59,11 +60,11 @@ import java.util.concurrent.locks.ReentrantLock;
* returns the count of both expired and unexpired elements.
* This queue does not permit null elements.
*
* <p>This class and its iterator implement all of the
* <em>optional</em> methods of the {@link Collection} and {@link
* Iterator} interfaces. The Iterator provided in method {@link
* #iterator()} is <em>not</em> guaranteed to traverse the elements of
* the DelayQueue in any particular order.
* <p>This class and its iterator implement all of the <em>optional</em>
* methods of the {@link Collection} and {@link Iterator} interfaces.
* The Iterator provided in method {@link #iterator()} is <em>not</em>
* guaranteed to traverse the elements of the DelayQueue in any
* particular order.
*
* <p>This class is a member of the
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
@ -339,8 +340,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c) {
if (c == null)
throw new NullPointerException();
Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
final ReentrantLock lock = this.lock;
@ -365,8 +365,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c, int maxElements) {
if (c == null)
throw new NullPointerException();
Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
if (maxElements <= 0)

View File

@ -42,6 +42,7 @@ import java.util.AbstractQueue;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.locks.LockSupport;
@ -75,9 +76,8 @@ import java.util.concurrent.locks.ReentrantLock;
* is not guaranteed. However, a queue constructed with fairness set
* to {@code true} grants threads access in FIFO order.
*
* <p>This class and its iterator implement all of the
* <em>optional</em> methods of the {@link Collection} and {@link
* Iterator} interfaces.
* <p>This class and its iterator implement all of the <em>optional</em>
* methods of the {@link Collection} and {@link Iterator} interfaces.
*
* <p>This class is a member of the
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
@ -1112,15 +1112,12 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c) {
if (c == null)
throw new NullPointerException();
Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
int n = 0;
for (E e; (e = poll()) != null;) {
for (E e; (e = poll()) != null; n++)
c.add(e);
++n;
}
return n;
}
@ -1131,15 +1128,12 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c, int maxElements) {
if (c == null)
throw new NullPointerException();
Objects.requireNonNull(c);
if (c == this)
throw new IllegalArgumentException();
int n = 0;
for (E e; n < maxElements && (e = poll()) != null;) {
for (E e; n < maxElements && (e = poll()) != null; n++)
c.add(e);
++n;
}
return n;
}

View File

@ -1059,17 +1059,17 @@ public class ThreadLocalRandom extends Random {
static {
try {
SEED = U.objectFieldOffset
(Thread.class.getDeclaredField("threadLocalRandomSeed"));
(Thread.class.getDeclaredField("threadLocalRandomSeed"));
PROBE = U.objectFieldOffset
(Thread.class.getDeclaredField("threadLocalRandomProbe"));
(Thread.class.getDeclaredField("threadLocalRandomProbe"));
SECONDARY = U.objectFieldOffset
(Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
(Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
THREADLOCALS = U.objectFieldOffset
(Thread.class.getDeclaredField("threadLocals"));
(Thread.class.getDeclaredField("threadLocals"));
INHERITABLETHREADLOCALS = U.objectFieldOffset
(Thread.class.getDeclaredField("inheritableThreadLocals"));
(Thread.class.getDeclaredField("inheritableThreadLocals"));
INHERITEDACCESSCONTROLCONTEXT = U.objectFieldOffset
(Thread.class.getDeclaredField("inheritedAccessControlContext"));
(Thread.class.getDeclaredField("inheritedAccessControlContext"));
} catch (ReflectiveOperationException e) {
throw new Error(e);
}

View File

@ -425,11 +425,11 @@ public class LockSupport {
static {
try {
PARKBLOCKER = U.objectFieldOffset
(Thread.class.getDeclaredField("parkBlocker"));
(Thread.class.getDeclaredField("parkBlocker"));
SECONDARY = U.objectFieldOffset
(Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
(Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
TID = U.objectFieldOffset
(Thread.class.getDeclaredField("tid"));
(Thread.class.getDeclaredField("tid"));
} catch (ReflectiveOperationException e) {
throw new Error(e);

View File

@ -35,7 +35,7 @@ import java.util.*;
public class CheckForComodification {
private static final int LENGTH = 10;
public static void main(String[] args) throws Exception {
List<Integer> list = new ArrayList<Integer>();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < LENGTH; i++)
list.add(i);
try {

View File

@ -32,7 +32,7 @@ import java.util.*;
@SuppressWarnings({"serial","unchecked"})
public class Bug6533203 {
void test(String[] args) throws Throwable {
final List<Integer> superstitious = new ArrayList<Integer>() {
final List<Integer> superstitious = new ArrayList<>() {
public void add(int index, Integer i) {
if (i == 13) throw new Error("unlucky");
else super.add(index, i); }};

View File

@ -209,8 +209,8 @@ public class IteratorMicroBenchmark {
// iterations, size, warmupSeconds, filter);
final ConcurrentSkipListMap<Integer,Integer> m
= new ConcurrentSkipListMap<Integer,Integer>();
final ArrayList<Integer> al = new ArrayList<Integer>(size);
= new ConcurrentSkipListMap<>();
final ArrayList<Integer> al = new ArrayList<>(size);
// Populate collections with random data
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
@ -218,16 +218,16 @@ public class IteratorMicroBenchmark {
m.put(rnd.nextInt(size), rnd.nextInt(size));
al.add(rnd.nextInt(size));
}
final Vector<Integer> v = new Vector<Integer>(al);
final ArrayDeque<Integer> ad = new ArrayDeque<Integer>(al);
final Vector<Integer> v = new Vector<>(al);
final ArrayDeque<Integer> ad = new ArrayDeque<>(al);
// shuffle ArrayDeque elements so they wrap
for (int i = 0, n = rnd.nextInt(size); i < n; i++)
ad.addLast(ad.removeFirst());
// Also test "short" collections
final int shortSize = 5;
final Vector<Integer> sv = new Vector<Integer>(v.subList(0, shortSize));
final ArrayList<Integer> sal = new ArrayList<Integer>(sv);
final Vector<Integer> sv = new Vector<>(v.subList(0, shortSize));
final ArrayList<Integer> sal = new ArrayList<>(sv);
// Checks for correctness *and* prevents loop optimizations
class Check {
@ -613,8 +613,7 @@ public class IteratorMicroBenchmark {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
int sum = 0;
List<Iterator<Integer>> its
= new ArrayList<Iterator<Integer>>(2);
List<Iterator<Integer>> its = new ArrayList<>(2);
its.add(v.iterator());
its.add(al.iterator());
for (int k = 0; its.get(k).hasNext(); k = (k == 0) ? 1 : 0)

View File

@ -159,7 +159,7 @@ public class RangeCheckMicroBenchmark {
final int size = intArg(args, "size", 1000);
final Pattern filter = patternArg(args, "filter");
final ArrayList<Integer> list = new ArrayList<Integer>();
final ArrayList<Integer> list = new ArrayList<>();
final Random rnd = new Random();
for (int i = 0; i < size; i++)
list.add(rnd.nextInt());

View File

@ -255,7 +255,7 @@ public class IteratorMicroBenchmark {
// "iterations=%d size=%d, warmup=%1g, filter=\"%s\"%n",
// iterations, size, warmupSeconds, filter);
final ArrayList<Integer> al = new ArrayList<Integer>(size);
final ArrayList<Integer> al = new ArrayList<>(size);
// Populate collections with random data
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
@ -307,14 +307,14 @@ public class IteratorMicroBenchmark {
for (Integer n : x)
sum += n;
check.sum(sum);}}},
new Job(klazz + " .iterator().forEachRemaining()") {
new Job(klazz + " iterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.iterator().forEachRemaining(n -> sum[0] += n);
check.sum(sum[0]);}}},
new Job(klazz + " .spliterator().tryAdvance()") {
new Job(klazz + " spliterator().tryAdvance()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
@ -322,28 +322,49 @@ public class IteratorMicroBenchmark {
Spliterator<Integer> spliterator = x.spliterator();
do {} while (spliterator.tryAdvance(n -> sum[0] += n));
check.sum(sum[0]);}}},
new Job(klazz + " .spliterator().forEachRemaining()") {
new Job(klazz + " spliterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.spliterator().forEachRemaining(n -> sum[0] += n);
check.sum(sum[0]);}}},
new Job(klazz + " .removeIf") {
new Job(klazz + " removeIf") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.removeIf(n -> { sum[0] += n; return false; });
if (x.removeIf(n -> { sum[0] += n; return false; }))
throw new AssertionError();
check.sum(sum[0]);}}},
new Job(klazz + " .forEach") {
new Job(klazz + " contains") {
public void work() throws Throwable {
int[] sum = new int[1];
Object y = new Object() {
public boolean equals(Object z) {
sum[0] += (int) z; return false; }};
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
if (x.contains(y)) throw new AssertionError();
check.sum(sum[0]);}}},
new Job(klazz + " remove(Object)") {
public void work() throws Throwable {
int[] sum = new int[1];
Object y = new Object() {
public boolean equals(Object z) {
sum[0] += (int) z; return false; }};
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
if (x.remove(y)) throw new AssertionError();
check.sum(sum[0]);}}},
new Job(klazz + " forEach") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
sum[0] = 0;
x.forEach(n -> sum[0] += n);
check.sum(sum[0]);}}},
new Job(klazz + " .toArray()") {
new Job(klazz + " toArray()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {
@ -351,7 +372,7 @@ public class IteratorMicroBenchmark {
for (Object o : x.toArray())
sum[0] += (Integer) o;
check.sum(sum[0]);}}},
new Job(klazz + " .toArray(a)") {
new Job(klazz + " toArray(a)") {
public void work() throws Throwable {
Integer[] a = new Integer[x.size()];
int[] sum = new int[1];
@ -361,7 +382,7 @@ public class IteratorMicroBenchmark {
for (Object o : a)
sum[0] += (Integer) o;
check.sum(sum[0]);}}},
new Job(klazz + " .toArray(empty)") {
new Job(klazz + " toArray(empty)") {
public void work() throws Throwable {
Integer[] empty = new Integer[0];
int[] sum = new int[1];
@ -370,12 +391,12 @@ public class IteratorMicroBenchmark {
for (Integer o : x.toArray(empty))
sum[0] += o;
check.sum(sum[0]);}}},
new Job(klazz + " .stream().collect") {
new Job(klazz + " stream().collect") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
check.sum(x.stream()
.collect(summingInt(e -> e)));}}},
new Job(klazz + " .parallelStream().collect") {
new Job(klazz + " parallelStream().collect") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
check.sum(x.parallelStream()
@ -385,7 +406,7 @@ public class IteratorMicroBenchmark {
List<Job> dequeJobs(Deque<Integer> x) {
String klazz = x.getClass().getSimpleName();
return List.of(
new Job(klazz + " .descendingIterator() loop") {
new Job(klazz + " descendingIterator() loop") {
public void work() throws Throwable {
for (int i = 0; i < iterations; i++) {
int sum = 0;
@ -393,7 +414,7 @@ public class IteratorMicroBenchmark {
while (it.hasNext())
sum += it.next();
check.sum(sum);}}},
new Job(klazz + " .descendingIterator().forEachRemaining()") {
new Job(klazz + " descendingIterator().forEachRemaining()") {
public void work() throws Throwable {
int[] sum = new int[1];
for (int i = 0; i < iterations; i++) {

View File

@ -678,7 +678,7 @@ public class MOAT {
private static void testQueueAddRemove(final Queue<Integer> q,
final Integer e) {
final List<Integer> originalContents = new ArrayList<Integer>(q);
final List<Integer> originalContents = new ArrayList<>(q);
final boolean isEmpty = q.isEmpty();
final boolean isList = (q instanceof List);
final List asList = isList ? (List) q : null;
@ -1207,8 +1207,7 @@ public class MOAT {
private static void throwsConsistently(Class<? extends Throwable> k,
Iterable<Fun> fs) {
List<Class<? extends Throwable>> threw
= new ArrayList<Class<? extends Throwable>>();
List<Class<? extends Throwable>> threw = new ArrayList<>();
for (Fun f : fs)
try { f.f(); threw.add(null); }
catch (Throwable t) {
@ -1224,7 +1223,7 @@ public class MOAT {
final ConcurrentMap<T,Integer> cm = (m instanceof ConcurrentMap)
? (ConcurrentMap<T,Integer>) m
: null;
List<Fun> fs = new ArrayList<Fun>();
List<Fun> fs = new ArrayList<>();
fs.add(() -> check(! m.containsKey(null)));
fs.add(() -> equal(m.remove(null), null));
fs.add(() -> equal(m.get(null), null));

View File

@ -38,7 +38,7 @@ public class BigBinarySearch {
extends AbstractList<Integer>
implements RandomAccess
{
private Map<Integer,Integer> m = new HashMap<Integer,Integer>();
private Map<Integer,Integer> m = new HashMap<>();
public Integer get(int i) {
if (i < 0) throw new IndexOutOfBoundsException(""+i);

View File

@ -42,7 +42,7 @@ public class Disjoint {
int x = 0;
for (int i = 0; i < N; i++) {
int size = rnd.nextInt(10) + 2;
List<Integer> list = new ArrayList<Integer>(size);
List<Integer> list = new ArrayList<>(size);
for (int j = 1; j < size; j++)
list.add(x++);
list.add(x);

View File

@ -184,8 +184,7 @@ public class RacingCollections {
}
private static List<Map<Integer, Boolean>> newConcurrentMaps() {
List<Map<Integer, Boolean>> list =
new ArrayList<Map<Integer, Boolean>>();
List<Map<Integer, Boolean>> list = new ArrayList<>();
list.add(new ConcurrentHashMap<Integer, Boolean>());
list.add(new ConcurrentSkipListMap<Integer, Boolean>());
return list;
@ -196,7 +195,7 @@ public class RacingCollections {
list.add(new Hashtable<Integer, Boolean>());
list.add(new HashMap<Integer, Boolean>());
list.add(new TreeMap<Integer, Boolean>());
Comparator<Integer> cmp = new Comparator<Integer>() {
Comparator<Integer> cmp = new Comparator<>() {
public int compare(Integer x, Integer y) {
return x - y;
}};
@ -205,7 +204,7 @@ public class RacingCollections {
}
private static List<Set<Integer>> newConcurrentSets() {
List<Set<Integer>> list = new ArrayList<Set<Integer>>();
List<Set<Integer>> list = new ArrayList<>();
list.add(new ConcurrentSkipListSet<Integer>());
list.add(new CopyOnWriteArraySet<Integer>());
return list;
@ -220,7 +219,7 @@ public class RacingCollections {
}
private static List<List<Integer>> newConcurrentLists() {
List<List<Integer>> list = new ArrayList<List<Integer>>();
List<List<Integer>> list = new ArrayList<>();
list.add(new CopyOnWriteArrayList<Integer>());
return list;
}
@ -233,8 +232,7 @@ public class RacingCollections {
}
private static List<Queue<Integer>> newConcurrentQueues() {
List<Queue<Integer>> list =
new ArrayList<Queue<Integer>>(newConcurrentDeques());
List<Queue<Integer>> list = new ArrayList<>(newConcurrentDeques());
list.add(new ArrayBlockingQueue<Integer>(10));
list.add(new LinkedBlockingQueue<Integer>(10));
list.add(new LinkedTransferQueue<Integer>());
@ -243,14 +241,13 @@ public class RacingCollections {
}
private static List<Queue<Integer>> newQueues() {
List<Queue<Integer>> list =
new ArrayList<Queue<Integer>>(newDeques());
List<Queue<Integer>> list = new ArrayList<>(newDeques());
list.add(new LinkedBlockingQueue<Integer>(10));
return list;
}
private static List<Deque<Integer>> newConcurrentDeques() {
List<Deque<Integer>> list = new ArrayList<Deque<Integer>>();
List<Deque<Integer>> list = new ArrayList<>();
list.add(new LinkedBlockingDeque<Integer>(10));
list.add(new ConcurrentLinkedDeque<Integer>());
return list;

View File

@ -67,7 +67,7 @@ public class ReverseOrder2 {
equal(list, golden);
}
private static Comparator<String> cmp = new Comparator<String> () {
private static Comparator<String> cmp = new Comparator<>() {
public int compare(String s1, String s2) {
int i1 = Integer.parseInt(s1);
int i2 = Integer.parseInt(s2);
@ -75,7 +75,7 @@ public class ReverseOrder2 {
}
};
private static final List<String> golden = new ArrayList<String>(N);
private static final List<String> golden = new ArrayList<>(N);
static {
for (int i = N-1; i >= 0; i--)
golden.add(String.valueOf(i));
@ -89,7 +89,7 @@ public class ReverseOrder2 {
equal(list, golden2);
}
private static final List<Integer> golden2 = new ArrayList<Integer>(N);
private static final List<Integer> golden2 = new ArrayList<>(N);
static {
for (int i = N-1; i >= 0; i--)
golden2.add(i);

View File

@ -49,7 +49,7 @@ public class SetFromMap {
private static void realMain() throws Throwable {
try {
Map<String,Boolean> m = new IdentityHashMap<String,Boolean>();
Map<String,Boolean> m = new IdentityHashMap<>();
Set<String> s = Collections.newSetFromMap(m);
String foo1 = new String("foo");
String foo2 = new String("foo");

View File

@ -131,7 +131,7 @@ public class ChorusLine {
}}};
private static void realMain(String[] args) throws Throwable {
Collection<Deque<Integer>> deqs = new ArrayDeque<Deque<Integer>>(3);
Collection<Deque<Integer>> deqs = new ArrayDeque<>(3);
deqs.add(new ArrayDeque<Integer>());
deqs.add(new LinkedList<Integer>());
deqs.add(new LinkedBlockingDeque<Integer>());
@ -157,12 +157,12 @@ public class ChorusLine {
prev = deq;
}
Deque<Iterator<Integer>> its = new ArrayDeque<Iterator<Integer>>();
Deque<Iterator<Integer>> its = new ArrayDeque<>();
for (Deque<Integer> deq : deqs)
its.addLast(deq.iterator());
equal(its);
Deque<Iterator<Integer>> dits = new ArrayDeque<Iterator<Integer>>();
Deque<Iterator<Integer>> dits = new ArrayDeque<>();
for (Deque<Integer> deq : deqs)
dits.addLast(deq.descendingIterator());
equal(dits);

View File

@ -36,11 +36,10 @@ public class ToArray {
// new ArrayList(IdentityHashMap.entrySet())
// used to return bogus entries.
//----------------------------------------------------------------
Map<String,String> mm = new IdentityHashMap<String,String>();
Map<String,String> mm = new IdentityHashMap<>();
mm.put("foo", "bar");
mm.put("baz", "quux");
List<Map.Entry<String,String>> lm
= new ArrayList<Map.Entry<String,String>>(mm.entrySet());
List<Map.Entry<String,String>> lm = new ArrayList<>(mm.entrySet());
String s = lm.toString();
if (! (s.equals("[foo=bar, baz=quux]") ||
s.equals("[baz=quux, foo=bar]")))
@ -65,8 +64,7 @@ public class ToArray {
// IdentityHashMap.entrySet().toArray(T[] a) used to simply
// return toArray() !
//----------------------------------------------------------------
IdentityHashMap<Integer,Integer> map
= new IdentityHashMap<Integer,Integer>();
IdentityHashMap<Integer,Integer> map = new IdentityHashMap<>();
Set<Map.Entry<Integer,Integer>> es = map.entrySet();
if (es.toArray().length != 0)
throw new Error("non-empty");

View File

@ -32,7 +32,7 @@ import java.util.*;
public class ToString {
public static void main(String[] args) {
Map<String, String> m = new IdentityHashMap<String, String>();
Map<String, String> m = new IdentityHashMap<>();
Set<Map.Entry<String, String>> es = m.entrySet();
m.put("beer", "good");
Iterator<Map.Entry<String, String>> i = es.iterator();

View File

@ -753,7 +753,7 @@ public class LockStep {
List<NavigableMap> maps = Arrays.asList(m1, m2);
for (NavigableMap m : maps) testEmptyMap(m);
final Set<Integer> ints = new HashSet<Integer>();
final Set<Integer> ints = new HashSet<>();
while (ints.size() < size)
ints.add(rnd.nextInt(1024));
final Integer[] elts = ints.toArray(new Integer[size]);
@ -795,7 +795,7 @@ public class LockStep {
List<NavigableSet> sets = Arrays.asList(s1, s2);
for (NavigableSet s : sets) testEmptySet(s);
final Set<Integer> ints = new HashSet<Integer>();
final Set<Integer> ints = new HashSet<>();
while (ints.size() < size)
ints.add(rnd.nextInt(1024));
final Integer[] elts = ints.toArray(new Integer[size]);

View File

@ -61,7 +61,7 @@ public class ForgetMeNot {
}
private static void realMain(String[] args) throws Throwable {
final PriorityQueue<Integer> q = new PriorityQueue<Integer>();
final PriorityQueue<Integer> q = new PriorityQueue<>();
Iterator<Integer> it;
//----------------------------------------------------------------

View File

@ -51,7 +51,7 @@ import java.util.concurrent.PriorityBlockingQueue;
public class NoNulls {
void test(String[] args) throws Throwable {
final Comparator<String> nullTolerantComparator
= new Comparator<String>() {
= new Comparator<>() {
public int compare(String x, String y) {
return (x == null ? -1 :
y == null ? 1 :
@ -63,7 +63,7 @@ public class NoNulls {
nullSortedSet.add(null);
final PriorityQueue<String> nullPriorityQueue
= new PriorityQueue<String>() {
= new PriorityQueue<>() {
public Object[] toArray() { return new Object[] { null };}};
final Collection<String> nullCollection = new ArrayList<>();

View File

@ -62,31 +62,31 @@ public class PriorityQueueSort {
if (args.length > 0)
n = Integer.parseInt(args[0]);
List<Integer> sorted = new ArrayList<Integer>(n);
List<Integer> sorted = new ArrayList<>(n);
for (int i = 0; i < n; i++)
sorted.add(new Integer(i));
List<Integer> shuffled = new ArrayList<Integer>(sorted);
List<Integer> shuffled = new ArrayList<>(sorted);
Collections.shuffle(shuffled);
Queue<Integer> pq = new PriorityQueue<Integer>(n, new MyComparator());
Queue<Integer> pq = new PriorityQueue<>(n, new MyComparator());
for (Iterator<Integer> i = shuffled.iterator(); i.hasNext(); )
pq.add(i.next());
List<Integer> recons = new ArrayList<Integer>();
List<Integer> recons = new ArrayList<>();
while (!pq.isEmpty())
recons.add(pq.remove());
if (!recons.equals(sorted))
throw new RuntimeException("Sort test failed");
recons.clear();
pq = new PriorityQueue<Integer>(shuffled);
pq = new PriorityQueue<>(shuffled);
while (!pq.isEmpty())
recons.add(pq.remove());
if (!recons.equals(sorted))
throw new RuntimeException("Sort test failed");
// Remove all odd elements from queue
pq = new PriorityQueue<Integer>(shuffled);
pq = new PriorityQueue<>(shuffled);
for (Iterator<Integer> i = pq.iterator(); i.hasNext(); )
if ((i.next().intValue() & 1) == 1)
i.remove();

View File

@ -69,7 +69,7 @@ public class RemoveContains {
}
public static void main(String[] args) {
final Comparator<String> firstChar = new Comparator<String>() {
final Comparator<String> firstChar = new Comparator<>() {
public int compare(String x, String y) {
return x.charAt(0) - y.charAt(0); }};

View File

@ -61,7 +61,7 @@ public class DistinctSeeds {
}
final int threadCount = 2;
List<RandomCollector> collectors = new ArrayList<>();
List<Thread> threads = new ArrayList<Thread>();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < threadCount; i++) {
RandomCollector r = new RandomCollector();
collectors.add(r);
@ -72,7 +72,7 @@ public class DistinctSeeds {
for (Thread thread : threads)
thread.join();
int collisions = 0;
HashSet<Long> s = new HashSet<Long>();
HashSet<Long> s = new HashSet<>();
for (RandomCollector r : collectors) {
for (long x : r.randoms) {
if (s.contains(x))

View File

@ -64,7 +64,7 @@ public class NullAtEnd {
}
private static final Comparator<String> NULL_AT_END
= new Comparator<String>() {
= new Comparator<>() {
/**
* Allows for nulls. Null is greater than anything non-null.
*/
@ -78,14 +78,13 @@ public class NullAtEnd {
public static void main(String[] args) {
try {
SortedMap<String,String> m1
= new TreeMap<String,String>(NULL_AT_END);
SortedMap<String,String> m1 = new TreeMap<>(NULL_AT_END);
check(eq(m1.put("a", "a"), null));
check(eq(m1.put("b", "b"), null));
check(eq(m1.put("c", "c"), null));
check(eq(m1.put(null, "d"), null));
SortedMap<String,String> m2 = new TreeMap<String,String>(m1);
SortedMap<String,String> m2 = new TreeMap<>(m1);
check(eq(m1.lastKey(), null));
check(eq(m1.get(m1.lastKey()), "d"));

View File

@ -36,7 +36,7 @@ import java.util.concurrent.atomic.*;
public class CopyInto {
private static void realMain(String[] args) throws Throwable {
try {
Vector<String> v = new Vector<String>();
Vector<String> v = new Vector<>();
v.add("foo");
v.copyInto(new Integer[3]);
fail("Expected ArrayStoreException");

View File

@ -86,26 +86,24 @@ public class IteratorConsistency {
}
Object itrs(ArrayBlockingQueue q) {
try {
return itrsField.get(q);
} catch (Throwable t) { throw new Error(); }
try { return itrsField.get(q); }
catch (Throwable ex) { throw new AssertionError(ex); }
}
int takeIndex(ArrayBlockingQueue q) {
try {
return takeIndexField.getInt(q);
} catch (Throwable t) { throw new Error(); }
try { return takeIndexField.getInt(q); }
catch (Throwable ex) { throw new AssertionError(ex); }
}
List<Iterator> trackedIterators(Object itrs) {
try {
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
if (itrs != null)
for (Object p = headField.get(itrs); p != null; p = nextField.get(p))
its.add(((WeakReference<Iterator>)(p)).get());
Collections.reverse(its);
return its;
} catch (Throwable t) { throw new Error(); }
} catch (Throwable ex) { throw new AssertionError(ex); }
}
List<Iterator> trackedIterators(ArrayBlockingQueue q) {
@ -114,7 +112,7 @@ public class IteratorConsistency {
List<Iterator> attachedIterators(Object itrs) {
try {
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
if (itrs != null)
for (Object p = headField.get(itrs); p != null; p = nextField.get(p)) {
Iterator it = ((WeakReference<Iterator>)(p)).get();
@ -123,7 +121,7 @@ public class IteratorConsistency {
}
Collections.reverse(its);
return its;
} catch (Throwable t) { unexpected(t); return null; }
} catch (Throwable ex) { unexpected(ex); return null; }
}
List<Iterator> attachedIterators(ArrayBlockingQueue q) {
@ -131,9 +129,8 @@ public class IteratorConsistency {
}
Object[] internalArray(ArrayBlockingQueue q) {
try {
return (Object[]) itemsField.get(q);
} catch (Throwable t) { throw new Error(t); }
try { return (Object[]) itemsField.get(q); }
catch (Throwable ex) { throw new AssertionError(ex); }
}
void printInternalArray(ArrayBlockingQueue q) {
@ -242,7 +239,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
check(q.add(i));
check(itrs(q) == null);
@ -268,7 +265,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
check(itrs(q) == null);
@ -295,7 +292,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
check(itrs(q) == null);
@ -366,7 +363,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
for (int i = 0; i < capacity; i++) {
@ -404,7 +401,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
// Move takeIndex to middle
for (int i = 0; i < capacity/2; i++) {
check(q.add(i));
@ -444,7 +441,7 @@ public class IteratorConsistency {
}
equal(attachedIterators(q), its);
break;
default: throw new Error();
default: throw new AssertionError();
}
for (int i = 0; i < capacity; i++) {
@ -478,7 +475,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
for (int i = 0; i < capacity; i++) {
@ -501,8 +498,8 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> retained = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
List<Iterator> retained = new ArrayList<>();
final int size = 1 + rnd.nextInt(capacity);
for (int i = 0; i < size; i++)
q.add(i);
@ -537,7 +534,7 @@ public class IteratorConsistency {
// Expect around 8 sweeps per PROBE_HOP
final int SWEEPS_PER_PROBE_HOP = 8;
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
for (int i = 0; i < PROBE_HOP_COUNT * PROBE_HOP; i++) {
@ -568,7 +565,7 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity/2; i++) {
q.add(i);
q.remove();
@ -621,7 +618,7 @@ public class IteratorConsistency {
check(!q.contains(i));
equal(q.size(), size - 1);
break;
default: throw new Error();
default: throw new AssertionError();
}
checkRemoveThrowsISE(it);
check(isDetached(it));
@ -638,11 +635,9 @@ public class IteratorConsistency {
//----------------------------------------------------------------
try {
ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
Queue<Iterator> its0
= new ArrayDeque<Iterator>();
Queue<Iterator> itsMid
= new ArrayDeque<Iterator>();
List<Iterator> its = new ArrayList<Iterator>();
Queue<Iterator> its0 = new ArrayDeque<>();
Queue<Iterator> itsMid = new ArrayDeque<>();
List<Iterator> its = new ArrayList<>();
for (int i = 0; i < capacity; i++)
q.add(i);
for (int i = 0; i < 2 * capacity + 1; i++) {

View File

@ -42,7 +42,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.ArrayList;
import java.util.List;
import java.util.SplittableRandom;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
@ -55,6 +54,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import jdk.testlibrary.Utils;
@ -89,7 +89,6 @@ public class CancelledProducerConsumerLoops {
final CountDownLatch consumersInterrupted;
final LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
final CyclicBarrier barrier;
final SplittableRandom rnd = new SplittableRandom();
volatile boolean done = false;
CancelledProducerConsumerLoops(int npairs, BlockingQueue<Integer> queue) {
@ -109,7 +108,7 @@ public class CancelledProducerConsumerLoops {
cons[i] = pool.submit(new Consumer());
}
barrier.await();
Thread.sleep(rnd.nextInt(5));
Thread.sleep(ThreadLocalRandom.current().nextInt(5));
for (int i = 1; i < npairs; i++) {
if (!prods[i].cancel(true) ||

View File

@ -148,7 +148,7 @@ public class DrainToFails {
System.err.println(q.getClass().getSimpleName());
for (int i = 0; i < CAPACITY; i++)
q.add(i);
List<Thread> putters = new ArrayList<Thread>();
List<Thread> putters = new ArrayList<>();
for (int i = 0; i < 4; i++) {
Thread putter = new Thread(putter(q, 42 + i));
putters.add(putter);

View File

@ -82,7 +82,7 @@ public class Interrupt {
(q instanceof BlockingDeque<?>) ?
(BlockingDeque<Object>) q : null;
q.clear();
List<Fun> fs = new ArrayList<Fun>();
List<Fun> fs = new ArrayList<>();
fs.add(() -> q.take());
fs.add(() -> q.poll(LONG_DELAY_MS, MILLISECONDS));
if (deq != null) {

View File

@ -105,13 +105,13 @@ public class PollMemoryLeak {
}
ConcurrentHashMap<Class<?>, Collection<Field>> classFields
= new ConcurrentHashMap<Class<?>, Collection<Field>>();
= new ConcurrentHashMap<>();
Collection<Field> referenceFieldsOf(Class<?> k) {
Collection<Field> fields = classFields.get(k);
if (fields == null) {
fields = new ArrayDeque<Field>();
ArrayDeque<Field> allFields = new ArrayDeque<Field>();
ArrayDeque<Field> allFields = new ArrayDeque<>();
for (Class<?> c = k; c != null; c = c.getSuperclass())
for (Field field : c.getDeclaredFields())
if (!Modifier.isStatic(field.getModifiers())
@ -130,7 +130,7 @@ public class PollMemoryLeak {
}
Set<Object> retainedObjects(Object x) {
ArrayDeque<Object> todo = new ArrayDeque<Object>() {
ArrayDeque<Object> todo = new ArrayDeque<>() {
public void push(Object x) { if (x != null) super.push(x); }};
Set<Object> uniqueObjects = Collections.newSetFromMap(
new IdentityHashMap<Object, Boolean>());

View File

@ -51,7 +51,7 @@ import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SplittableRandom;
import java.util.concurrent.ThreadLocalRandom;
public class MapCheck {
@ -612,7 +612,7 @@ public class MapCheck {
}
static void shuffle(Object[] keys) {
SplittableRandom rnd = new SplittableRandom();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int size = keys.length;
for (int i=size; i>1; i--) {
int r = rnd.nextInt(i);

View File

@ -68,8 +68,7 @@ public class MapLoops {
static final ExecutorService pool = Executors.newCachedThreadPool();
static final List<Throwable> throwables
= new CopyOnWriteArrayList<Throwable>();
static final List<Throwable> throwables = new CopyOnWriteArrayList<>();
public static void main(String[] args) throws Exception {

View File

@ -101,13 +101,13 @@ public class RemoveLeak {
}
ConcurrentHashMap<Class<?>, Collection<Field>> classFields
= new ConcurrentHashMap<Class<?>, Collection<Field>>();
= new ConcurrentHashMap<>();
Collection<Field> referenceFieldsOf(Class<?> k) {
Collection<Field> fields = classFields.get(k);
if (fields == null) {
fields = new ArrayDeque<Field>();
ArrayDeque<Field> allFields = new ArrayDeque<Field>();
ArrayDeque<Field> allFields = new ArrayDeque<>();
for (Class<?> c = k; c != null; c = c.getSuperclass())
for (Field field : c.getDeclaredFields())
if (!Modifier.isStatic(field.getModifiers())
@ -126,7 +126,7 @@ public class RemoveLeak {
}
Set<Object> retainedObjects(Object x) {
ArrayDeque<Object> todo = new ArrayDeque<Object>() {
ArrayDeque<Object> todo = new ArrayDeque<>() {
public void push(Object x) { if (x != null) super.push(x); }};
Set<Object> uniqueObjects = Collections.newSetFromMap(
new IdentityHashMap<Object, Boolean>());

View File

@ -28,7 +28,7 @@
* @summary Test removeIf on views of concurrent maps
*/
import org.testng.Assert;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -54,8 +54,8 @@ public class ConcurrentRemoveIf {
static final int SIZE = 1000;
static final int HALF_SIZE = SIZE / 2;
@DataProvider(name = "String,Supplier<ConcurrentMap>,Runnable")
public static Object[][] spliteratorDataProvider() {
@DataProvider()
public static Object[][] concurrentMapViewRemoveIfActions() {
List<Object[]> rows = new ArrayList<>();
// ConcurrentMap classes to test
@ -95,24 +95,17 @@ public class ConcurrentRemoveIf {
dm.values().removeIf(v -> v == 0);
});
for (Map.Entry<String, Supplier<ConcurrentMap<Integer, Integer>>> mapSupplier : maps.entrySet()) {
Supplier<ConcurrentMap<Integer, Integer>> sm = mapSupplier.getValue();
for (Map.Entry<String, Consumer<ConcurrentMap<Integer, Integer>>> action : actions.entrySet()) {
rows.add(new Object[]{
mapSupplier.getKey() + action.getKey(),
sm,
action.getValue()});
}
maps.forEach((mapDescription, sm) -> {
actions.forEach((actionDescription, action) -> {
rows.add(new Object[] {mapDescription + actionDescription, sm, action});
});
if (sm.get() instanceof ConcurrentNavigableMap) {
for (Map.Entry<String, Consumer<ConcurrentNavigableMap<Integer, Integer>>> action : navActions.entrySet()) {
rows.add(new Object[]{
mapSupplier.getKey() + action.getKey(),
sm,
action.getValue()});
}
navActions.forEach((actionDescription, action) -> {
rows.add(new Object[] {mapDescription + actionDescription, sm, action});
});
}
}
});
return rows.toArray(new Object[0][]);
}
@ -124,7 +117,7 @@ public class ConcurrentRemoveIf {
executorService.shutdown();
}
@Test(dataProvider = "String,Supplier<ConcurrentMap>,Runnable")
@Test(dataProvider = "concurrentMapViewRemoveIfActions")
public void testMap(String desc, Supplier<ConcurrentMap<Integer, Integer>> ms, Consumer<ConcurrentMap<Integer, Integer>> action)
throws InterruptedException {
for (int i = 0; i < K; i++) {
@ -140,7 +133,7 @@ public class ConcurrentRemoveIf {
// To start working simultaneously
CyclicBarrier threadStarted = new CyclicBarrier(2);
// This task put 1's into map
// This task puts 1's into map
CompletableFuture<Void> putter = CompletableFuture.runAsync(
awaitOn(threadStarted, () -> fillMap(map, 1)),
executorService);
@ -153,7 +146,8 @@ public class ConcurrentRemoveIf {
// Wait for both tasks to complete
CompletableFuture.allOf(putter, remover).join();
Assert.assertEquals(map.size(), SIZE, "Map size incorrect");
assertEquals(map.size(), SIZE, "Map size incorrect");
map.forEach((k, v) -> assertEquals(v, (Integer)1));
}
static void fillMap(ConcurrentMap<Integer, Integer> map, int value) {

View File

@ -73,7 +73,7 @@ public class ConcurrentQueueLoops {
int items = 1024 * 1024;
Collection<Queue<Integer>> concurrentQueues() {
List<Queue<Integer>> queues = new ArrayList<Queue<Integer>>();
List<Queue<Integer>> queues = new ArrayList<>();
queues.add(new ConcurrentLinkedDeque<Integer>());
queues.add(new ConcurrentLinkedQueue<Integer>());
queues.add(new ArrayBlockingQueue<Integer>(items, false));
@ -166,7 +166,7 @@ public class ConcurrentQueueLoops {
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(n + 1, timer);
totalItems = new AtomicInteger(n * items);
ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>(n);
ArrayList<Future<Integer>> results = new ArrayList<>(n);
for (int i = 0; i < n; ++i)
results.add(pool.submit(new Stage(q, barrier, items)));

View File

@ -82,10 +82,10 @@ public class GCRetention {
throw new AssertionError("failed to do a \"full\" gc");
}
final Map<String,String> results = new ConcurrentHashMap<String,String>();
final Map<String,String> results = new ConcurrentHashMap<>();
Collection<Queue<Boolean>> queues() {
List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
List<Queue<Boolean>> queues = new ArrayList<>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false));
@ -107,7 +107,7 @@ public class GCRetention {
}
void prettyPrintResults() {
List<String> classNames = new ArrayList<String>(results.keySet());
List<String> classNames = new ArrayList<>(results.keySet());
Collections.sort(classNames);
int maxClassNameLength = 0;
int maxNanosLength = 0;

View File

@ -195,7 +195,7 @@ public class IteratorWeakConsistency {
((BlockingQueue)q).remainingCapacity() :
Integer.MAX_VALUE;
final int capacity = Math.min(20, remainingCapacity);
List<Iterator> its = new ArrayList<Iterator>();
List<Iterator> its = new ArrayList<>();
// Move to "middle"
for (int i = 0; i < capacity/2; i++) {
check(q.add(i));
@ -229,7 +229,7 @@ public class IteratorWeakConsistency {
it.remove();
}
break;
default: throw new Error();
default: throw new AssertionError();
}
for (int i = 0; i < capacity; i++) {

View File

@ -59,10 +59,10 @@ public class RemovePollRace {
// Suitable for benchmarking. Overridden by args[0] for testing.
int count = 1024 * 1024;
final Map<String,String> results = new ConcurrentHashMap<String,String>();
final Map<String,String> results = new ConcurrentHashMap<>();
Collection<Queue<Boolean>> concurrentQueues() {
List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
List<Queue<Boolean>> queues = new ArrayList<>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false));
@ -81,7 +81,7 @@ public class RemovePollRace {
}
void prettyPrintResults() {
List<String> classNames = new ArrayList<String>(results.keySet());
List<String> classNames = new ArrayList<>(results.keySet());
Collections.sort(classNames);
int maxClassNameLength = 0;
int maxNanosLength = 0;
@ -173,9 +173,9 @@ public class RemovePollRace {
addersDone.countDown();
}};
final List<Thread> adders = new ArrayList<Thread>();
final List<Thread> removers = new ArrayList<Thread>();
final List<Thread> pollers = new ArrayList<Thread>();
final List<Thread> adders = new ArrayList<>();
final List<Thread> removers = new ArrayList<>();
final List<Thread> pollers = new ArrayList<>();
for (int i = 0; i < adderCount; i++)
adders.add(checkedThread(adder));
for (int i = 0; i < removerCount; i++)
@ -183,7 +183,7 @@ public class RemovePollRace {
for (int i = 0; i < pollerCount; i++)
pollers.add(checkedThread(poller));
final List<Thread> allThreads = new ArrayList<Thread>();
final List<Thread> allThreads = new ArrayList<>();
allThreads.addAll(removers);
allThreads.addAll(pollers);
allThreads.addAll(adders);

View File

@ -36,7 +36,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class EqualsRace {
private static void realMain(String[] args) throws Throwable {
final int iterations = 100000;
final List<Integer> list = new CopyOnWriteArrayList<Integer>();
final List<Integer> list = new CopyOnWriteArrayList<>();
final Integer one = Integer.valueOf(1);
final List<Integer> oneElementList = Arrays.asList(one);
final Thread t = new CheckedThread() { public void realRun() {

View File

@ -40,8 +40,8 @@ public class RacingCows {
final Integer three = Integer.valueOf(3);
//------------ CopyOnWriteArraySet -------------------------------
final Set<Integer> s1 = new CopyOnWriteArraySet<Integer>();
final Set<Integer> s2 = new CopyOnWriteArraySet<Integer>();
final Set<Integer> s1 = new CopyOnWriteArraySet<>();
final Set<Integer> s2 = new CopyOnWriteArraySet<>();
s1.add(1);
final Thread t1 = new CheckedThread() { public void realRun() {
@ -58,9 +58,9 @@ public class RacingCows {
t1.join();
//------------ CopyOnWriteArrayList ------------------------------
final List<Integer> l1 = new CopyOnWriteArrayList<Integer>();
final List<Integer> l2 = new CopyOnWriteArrayList<Integer>();
final List<Integer> l3 = new CopyOnWriteArrayList<Integer>();
final List<Integer> l1 = new CopyOnWriteArrayList<>();
final List<Integer> l2 = new CopyOnWriteArrayList<>();
final List<Integer> l3 = new CopyOnWriteArrayList<>();
l1.add(1);
final Thread t2 = new CheckedThread() { public void realRun() {

View File

@ -332,7 +332,7 @@ public class Basic {
//----------------------------------------------------------------
try {
final CountDownLatch doneSignal = new CountDownLatch(1);
final List<Waiter> waiters = new ArrayList<Waiter>(N);
final List<Waiter> waiters = new ArrayList<>(N);
// work around finality of closed-over variables
final Runnable[] realAction = new Runnable[1];
@ -379,7 +379,7 @@ public class Basic {
try {
final CountDownLatch doneSignal = new CountDownLatch(1);
final CyclicBarrier barrier = new CyclicBarrier(N+1);
final List<Waiter> waiters = new ArrayList<Waiter>(N);
final List<Waiter> waiters = new ArrayList<>(N);
for (int i = 0; i < N; i++) {
Waiter waiter = new Waiter(i < N/2, doneSignal, barrier);
waiter.start();

View File

@ -42,7 +42,7 @@ public class Iterate {
private static void realMain(String[] args) throws Throwable {
Godot[] godots = new Godot[] { new Godot(), new Godot(), new Godot() };
DelayQueue<Godot> q = new DelayQueue<Godot>(Arrays.asList(godots));
DelayQueue<Godot> q = new DelayQueue<>(Arrays.asList(godots));
Iterator<Godot> it = q.iterator();
q.clear();
check(it.hasNext());

View File

@ -39,7 +39,7 @@ public class PollUnexpired {
}
private static void realMain(String[] args) throws Throwable {
DelayQueue<Godot> q = new DelayQueue<Godot>();
DelayQueue<Godot> q = new DelayQueue<>();
for (int i = 0; i < 3; i++) {
equal(q.size(), i);
equal(q.poll(), null);

View File

@ -38,7 +38,7 @@ public class Stress {
public static void main(String[] args) throws Throwable {
final DelayQueue<Delayed> q = new DelayQueue<Delayed>();
final DelayQueue<Delayed> q = new DelayQueue<>();
final long t0 = System.nanoTime();
for (long i = 0; i < 1000; i++) {
final long expiry = t0 + i*10L*1000L*1000L;

View File

@ -116,8 +116,8 @@ public class ExchangeLoops {
barrier.await();
}
catch (Exception ie) {
ie.printStackTrace();
catch (Exception ex) {
ex.printStackTrace();
return;
}
}
@ -127,7 +127,7 @@ public class ExchangeLoops {
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(nthreads + 1, timer);
Exchanger<Int> l = null;
Exchanger<Int> r = new Exchanger<Int>();
Exchanger<Int> r = new Exchanger<>();
for (int i = 0; i < nthreads; ++i) {
pool.execute(new Stage(l, r, barrier, iters));
l = r;

View File

@ -45,7 +45,7 @@ import java.util.concurrent.Callable;
public class PrivilegedCallables {
Callable<Integer> real;
final Callable<Integer> realCaller = new Callable<Integer>() {
final Callable<Integer> realCaller = new Callable<>() {
public Integer call() throws Exception {
return real.call(); }};
@ -132,7 +132,7 @@ public class PrivilegedCallables {
for (int i = 0; i < 20; i++)
if (rnd.nextBoolean()) {
final Throwable t = randomThrowable();
real = new Callable<Integer>() {
real = new Callable<>() {
public Integer call() throws Exception {
throwThrowable(t);
return null; }};
@ -142,7 +142,7 @@ public class PrivilegedCallables {
} catch (Throwable tt) { check(t == tt); }
} else {
final int n = rnd.nextInt();
real = new Callable<Integer>() {
real = new Callable<>() {
public Integer call() { return n; }};
equal(c.call(), n);
}

View File

@ -55,8 +55,7 @@ public class BlockingTaskExecutor {
final NotificationReceiver notifiee1 = new NotificationReceiver();
final NotificationReceiver notifiee2 = new NotificationReceiver();
final Collection<Callable<Object>> tasks =
new ArrayList<Callable<Object>>();
final Collection<Callable<Object>> tasks = new ArrayList<>();
tasks.add(new BlockingTask(notifiee1));
tasks.add(new BlockingTask(notifiee2));
tasks.add(new NonBlockingTask());

View File

@ -119,7 +119,7 @@ public class Customized {
public void run() { throw new Error(); }};
try {
final MyFutureTask<Long> task = new MyFutureTask<Long>(nop, 42L);
final MyFutureTask<Long> task = new MyFutureTask<>(nop, 42L);
checkReady(task);
equalCounts(0,0,0);
check(task.runAndReset());
@ -136,7 +136,7 @@ public class Customized {
} catch (Throwable t) { unexpected(t); }
try {
final MyFutureTask<Long> task = new MyFutureTask<Long>(nop, 42L);
final MyFutureTask<Long> task = new MyFutureTask<>(nop, 42L);
cancel(task, false);
equalCounts(2,1,0);
cancel(task, false);
@ -147,7 +147,7 @@ public class Customized {
} catch (Throwable t) { unexpected(t); }
try {
final MyFutureTask<Long> task = new MyFutureTask<Long>(bad, 42L);
final MyFutureTask<Long> task = new MyFutureTask<>(bad, 42L);
checkReady(task);
run(task);
checkThrew(task);
@ -157,7 +157,7 @@ public class Customized {
} catch (Throwable t) { unexpected(t); }
try {
final MyFutureTask<Long> task = new MyFutureTask<Long>(nop, 42L);
final MyFutureTask<Long> task = new MyFutureTask<>(nop, 42L);
checkReady(task);
task.set(99L);
checkDone(task);
@ -170,7 +170,7 @@ public class Customized {
} catch (Throwable t) { unexpected(t); }
try {
final MyFutureTask<Long> task = new MyFutureTask<Long>(nop, 42L);
final MyFutureTask<Long> task = new MyFutureTask<>(nop, 42L);
checkReady(task);
task.setException(new Throwable());
checkThrew(task);

View File

@ -63,7 +63,7 @@ public class DoneMeansDone {
final AtomicBoolean done = new AtomicBoolean(false);
final AtomicReference<FutureTask<Boolean>> a = new AtomicReference<>();
final CountDownLatch threadsStarted = new CountDownLatch(nThreads);
final Callable<Boolean> alwaysTrue = new Callable<Boolean>() {
final Callable<Boolean> alwaysTrue = new Callable<>() {
public Boolean call() {
return true;
}};

View File

@ -66,9 +66,9 @@ public class DoneTimedGetLoops {
final long timeoutMillis = 10L * 1000L;
final AtomicReference<PublicFutureTask> normalRef
= new AtomicReference<PublicFutureTask>();
= new AtomicReference<>();
final AtomicReference<PublicFutureTask> abnormalRef
= new AtomicReference<PublicFutureTask>();
= new AtomicReference<>();
final Throwable throwable = new Throwable();

View File

@ -33,7 +33,7 @@ import java.util.concurrent.LinkedBlockingQueue;
public class ToArray {
public static void main(String[] args) throws Throwable {
Collection<Integer> c = new LinkedBlockingQueue<Integer>();
Collection<Integer> c = new LinkedBlockingQueue<>();
if (c.toArray(new Integer[]{42})[0] != null)
throw new Error("should be null");
}

View File

@ -52,7 +52,7 @@ public class Arrive {
final int n = ThreadLocalRandom.current().nextInt(1, 10);
final Phaser startingGate = new Phaser(n);
final Phaser phaser = new Phaser(n);
final List<Thread> threads = new ArrayList<Thread>();
final List<Thread> threads = new ArrayList<>();
final AtomicInteger count0 = new AtomicInteger(0);
final AtomicInteger count1 = new AtomicInteger(0);
final Runnable task = new Runnable() { public void run() {

View File

@ -69,8 +69,8 @@ public class Basic {
try {
equal(phase, phaser.awaitAdvanceInterruptibly(0));
equal(phase, phaser.awaitAdvanceInterruptibly(0, 10, SECONDS));
} catch (Exception ie) {
unexpected(ie);
} catch (Exception ex) {
unexpected(ex);
}
equal(phaser.getUnarrivedParties(), unarriverParties);
equal(phaser.getRegisteredParties(), registeredParties);
@ -323,7 +323,7 @@ public class Basic {
try {
Phaser phaser = new Phaser(1);
Iterator<Arriver> arrivers = arriverIterator(phaser);
LinkedList<Arriver> arriverList = new LinkedList<Arriver>();
LinkedList<Arriver> arriverList = new LinkedList<>();
int phase = phaser.getPhase();
for (int i = 1; i < 5; i++) {
startingGate = new Phaser(1+(3*i));

View File

@ -93,7 +93,7 @@ public class FickleRegister {
};
int reps = 4;
ArrayList<Thread> threads = new ArrayList<Thread>();
ArrayList<Thread> threads = new ArrayList<>();
for (int j = 0; j < reps; ++j) {
threads.add(new Thread(new Runner(subchild1)));
threads.add(new Thread(new Runner(child1)));

View File

@ -44,6 +44,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Supplier;
import jdk.testlibrary.RandomFactory;
public class ConfigChanges {
@ -124,6 +125,22 @@ public class ConfigChanges {
}
}
/**
* Waits for condition to become true, first spin-polling, then sleep-polling.
*/
static void spinAwait(Supplier<Boolean> waitingForGodot) {
for (int spins = 0; !waitingForGodot.get(); ) {
if ((spins = (spins + 1) & 3) > 0) {
Thread.yield();
} else {
try { Thread.sleep(4); }
catch (InterruptedException unexpected) {
throw new AssertionError(unexpected);
}
}
}
}
private static void realMain(String[] args) throws Throwable {
if (rnd.nextBoolean())
System.setSecurityManager(new PermissiveSecurityManger());
@ -210,10 +227,7 @@ public class ConfigChanges {
pumpedUp2.await();
pumpedUp.await();
while (tg.activeCount() != 2*n &&
tg.activeCount() != 2*n)
Thread.yield();
equal(2*n, tg.activeCount());
spinAwait(() -> tg.activeCount() == 2*n);
equal(2*n, tpe.getMaximumPoolSize());
equal(4*n, tpe.getLargestPoolSize());
@ -232,10 +246,7 @@ public class ConfigChanges {
long t0 = System.nanoTime();
tpe.setKeepAliveTime(7L, MILLISECONDS);
equal(7L, tpe.getKeepAliveTime(MILLISECONDS));
while (tg.activeCount() > n &&
tg.activeCount() > n)
Thread.sleep(4);
equal(n, tg.activeCount());
spinAwait(() -> tg.activeCount() == n);
check(System.nanoTime() - t0 >= tpe.getKeepAliveTime(NANOSECONDS));
//report("idle", tpe);
@ -243,10 +254,7 @@ public class ConfigChanges {
t0 = System.nanoTime();
tpe.allowCoreThreadTimeOut(true);
check(tpe.allowsCoreThreadTimeOut());
while (tg.activeCount() > 0 &&
tg.activeCount() > 0)
Thread.sleep(4);
equal(tg.activeCount(), 0);
spinAwait(() -> tg.activeCount() == 0);
// The following assertion is almost always true, but may
// exceptionally not be during a transition from core count

View File

@ -72,8 +72,7 @@ public class CoreThreadTimeOut {
void test(String[] args) throws Throwable {
final int threadCount = 10;
final int timeoutMillis = 30;
BlockingQueue<Runnable> q
= new ArrayBlockingQueue<Runnable>(2*threadCount);
BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(2*threadCount);
ThreadPoolExecutor tpe
= new ThreadPoolExecutor(threadCount, threadCount,
timeoutMillis, TimeUnit.MILLISECONDS,

View File

@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
public class ThrowingTasks {
static final Random rnd = new Random();
@ -139,7 +140,7 @@ public class ThrowingTasks {
public void run() { execute.run(); }
}
static final List<Flaky> flakes = new ArrayList<Flaky>();
static final List<Flaky> flakes = new ArrayList<>();
static {
for (Thrower x : throwers)
for (Thrower y : throwers)
@ -167,6 +168,22 @@ public class ThrowingTasks {
} catch (Throwable t) { unexpected(t); }
}
/**
* Waits for condition to become true, first spin-polling, then sleep-polling.
*/
static void spinAwait(Supplier<Boolean> waitingForGodot) {
for (int spins = 0; !waitingForGodot.get(); ) {
if ((spins = (spins + 1) & 3) > 0) {
Thread.yield();
} else {
try { Thread.sleep(4); }
catch (InterruptedException unexpected) {
throw new AssertionError(unexpected);
}
}
}
}
static class CheckingExecutor extends ThreadPoolExecutor {
private final ReentrantLock lock = new ReentrantLock();
CheckingExecutor() {
@ -238,10 +255,7 @@ public class ThrowingTasks {
//System.out.printf("thread count = %d%n", tg.activeCount());
uncaughtExceptionsLatch.await();
while (tg.activeCount() != tpe.getCorePoolSize() ||
tg.activeCount() != tpe.getCorePoolSize())
Thread.sleep(10);
equal(tg.activeCount(), tpe.getCorePoolSize());
spinAwait(() -> tg.activeCount() == tpe.getCorePoolSize());
tpe.shutdown();
@ -250,8 +264,7 @@ public class ThrowingTasks {
//while (tg.activeCount() > 0) Thread.sleep(10);
//System.out.println(uncaughtExceptions);
List<Map<Class<?>, Integer>> maps
= new ArrayList<Map<Class<?>, Integer>>();
List<Map<Class<?>, Integer>> maps = new ArrayList<>();
maps.add(uncaughtExceptions);
maps.add(uncaughtExceptionsTable);
for (Map<Class<?>, Integer> map : maps) {

View File

@ -48,11 +48,11 @@ public class Lazy {
final AtomicBoolean b = new AtomicBoolean();
final AtomicInteger i = new AtomicInteger();
final AtomicLong l = new AtomicLong();
final AtomicReference<Long> r = new AtomicReference<Long>();
final AtomicReference<Long> r = new AtomicReference<>();
final AtomicIntegerArray ia = new AtomicIntegerArray(1);
final AtomicLongArray la = new AtomicLongArray(1);
final AtomicReferenceArray<Long> ra = new AtomicReferenceArray<Long>(1);
final AtomicReferenceArray<Long> ra = new AtomicReferenceArray<>(1);
final AtomicIntegerFieldUpdater<Lazy> iu =
AtomicIntegerFieldUpdater.newUpdater(Lazy.class, "ii");

View File

@ -40,11 +40,11 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.SplittableRandom;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -53,7 +53,6 @@ import jdk.testlibrary.Utils;
public final class CheckedLockLoops {
static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
static ExecutorService pool;
static final SplittableRandom rnd = new SplittableRandom();
public static void main(String[] args) throws Exception {
final int maxThreads = (args.length > 0)
@ -73,7 +72,7 @@ public final class CheckedLockLoops {
static void oneTest(int nthreads, int iters) throws Exception {
System.out.println("Threads: " + nthreads);
int v = rnd.nextInt();
int v = ThreadLocalRandom.current().nextInt();
System.out.print("builtin lock ");
new BuiltinLockLoop().test(v, nthreads, iters);
@ -151,7 +150,7 @@ public final class CheckedLockLoops {
result += loop(iters);
barrier.await();
}
catch (Exception ie) {
catch (Exception ex) {
return;
}
}

View File

@ -42,7 +42,6 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.lang.ref.WeakReference;
import java.util.SplittableRandom;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@ -52,6 +51,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
@ -192,7 +192,7 @@ public class TimedAcquireLeak {
final String childClassName = Job.class.getName();
final String classToCheckForLeaks = Job.classToCheckForLeaks();
final String uniqueID =
String.valueOf(new SplittableRandom().nextInt(Integer.MAX_VALUE));
String.valueOf(ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE));
final String[] jobCmd = {
java, "-Xmx8m", "-XX:+UsePerfData",
@ -259,7 +259,7 @@ public class TimedAcquireLeak {
= rwlock.writeLock();
rwlock.writeLock().lock();
final BlockingQueue<Object> q = new LinkedBlockingQueue<Object>();
final BlockingQueue<Object> q = new LinkedBlockingQueue<>();
final Semaphore fairSem = new Semaphore(0, true);
final Semaphore unfairSem = new Semaphore(0, false);
//final int threads =
@ -275,7 +275,7 @@ public class TimedAcquireLeak {
for (int i = 0; i < threads; i++)
new Thread() { public void run() {
try {
final SplittableRandom rnd = new SplittableRandom();
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int j = 0; j < iterations; j++) {
if (j == iterations/10 || j == iterations - 1) {
cb.await(); // Quiesce

View File

@ -40,13 +40,11 @@
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.SplittableRandom;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.ReentrantLock;
public final class CancelledLockLoops {
static final SplittableRandom rnd = new SplittableRandom();
public static void main(String[] args) throws Exception {
final int maxThreads = (args.length > 0) ? Integer.parseInt(args[0]) : 5;
final int reps = 1; // increase for stress testing
@ -61,7 +59,7 @@ public final class CancelledLockLoops {
static final class Loops implements Runnable {
private final boolean print = false;
private volatile boolean done = false;
private int v = rnd.nextInt();
private int v = ThreadLocalRandom.current().nextInt();
private int completed = 0;
private volatile int result = 17;
private final ReentrantLock lock = new ReentrantLock();
@ -76,6 +74,7 @@ public final class CancelledLockLoops {
}
final void test() throws Exception {
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
Thread[] threads = new Thread[nthreads];
for (int i = 0; i < threads.length; ++i)
threads[i] = new Thread(this);

View File

@ -40,17 +40,16 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.SplittableRandom;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.ReentrantLock;
import jdk.testlibrary.Utils;
public final class LockOncePerThreadLoops {
static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
static final ExecutorService pool = Executors.newCachedThreadPool();
static final SplittableRandom rnd = new SplittableRandom();
static boolean print = false;
static int nlocks = 20_000;
static int nthreads = 20;
@ -75,7 +74,7 @@ public final class LockOncePerThreadLoops {
}
static final class ReentrantLockLoop implements Runnable {
private int v = rnd.nextInt();
private int v = ThreadLocalRandom.current().nextInt();
private volatile int result = 17;
final ReentrantLock[]locks = new ReentrantLock[nlocks];
@ -112,7 +111,7 @@ public final class LockOncePerThreadLoops {
for (int i = 0; i < locks.length; ++i) {
locks[i].lock();
try {
v = x += ~(v - i);
v = x += ~(v - i);
}
finally {
locks[i].unlock();
@ -127,7 +126,7 @@ public final class LockOncePerThreadLoops {
barrier.await();
result += sum;
}
catch (Exception ie) {
catch (Exception ex) {
return;
}
}

View File

@ -40,17 +40,16 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.SplittableRandom;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.ThreadLocalRandom;
import jdk.testlibrary.Utils;
public final class SimpleReentrantLockLoops {
static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
static final ExecutorService pool = Executors.newCachedThreadPool();
static final SplittableRandom rnd = new SplittableRandom();
static boolean print = false;
static int iters = 100_000;
@ -76,7 +75,7 @@ public final class SimpleReentrantLockLoops {
}
static final class ReentrantLockLoop implements Runnable {
private int v = rnd.nextInt();
private int v = ThreadLocalRandom.current().nextInt();
private volatile int result = 17;
private final ReentrantLock lock = new ReentrantLock();
private final LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
@ -132,7 +131,7 @@ public final class SimpleReentrantLockLoops {
barrier.await();
result += sum;
}
catch (Exception ie) {
catch (Exception ex) {
return;
}
}

View File

@ -40,10 +40,10 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.SplittableRandom;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import jdk.testlibrary.Utils;
@ -51,7 +51,6 @@ import jdk.testlibrary.Utils;
public final class TimeoutLockLoops {
static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
static final ExecutorService pool = Executors.newCachedThreadPool();
static final SplittableRandom rnd = new SplittableRandom();
static boolean print = false;
static final long TIMEOUT = 10;
@ -72,7 +71,7 @@ public final class TimeoutLockLoops {
}
static final class ReentrantLockLoop implements Runnable {
private int v = rnd.nextInt();
private int v = ThreadLocalRandom.current().nextInt();
private volatile int result = 17;
private final ReentrantLock lock = new ReentrantLock();
private final LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
@ -91,7 +90,7 @@ public final class TimeoutLockLoops {
lock.unlock();
}
barrier.await();
Thread.sleep(rnd.nextInt(5));
Thread.sleep(ThreadLocalRandom.current().nextInt(5));
while (!lock.tryLock()); // Jam lock
// lock.lock();
barrier.await();

View File

@ -294,7 +294,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAny3() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<Long>> l = new ArrayList<Callable<Long>>();
List<Callable<Long>> l = new ArrayList<>();
l.add(new Callable<Long>() {
public Long call() { throw new ArithmeticException(); }});
l.add(null);
@ -311,7 +311,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAny4() throws InterruptedException {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -328,7 +328,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAny5() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -366,7 +366,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAll3() throws InterruptedException {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -382,7 +382,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAll4() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -401,7 +401,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testInvokeAll5() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -430,7 +430,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAnyNullTimeUnit() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -459,7 +459,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAny3() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<Long>> l = new ArrayList<Callable<Long>>();
List<Callable<Long>> l = new ArrayList<>();
l.add(new Callable<Long>() {
public Long call() { throw new ArithmeticException(); }});
l.add(null);
@ -477,7 +477,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -496,7 +496,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -524,7 +524,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -550,7 +550,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAll3() throws InterruptedException {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -566,7 +566,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAll4() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures =
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
@ -586,7 +586,7 @@ public class AbstractExecutorServiceTest extends JSR166TestCase {
public void testTimedInvokeAll5() throws Exception {
final ExecutorService e = new DirectExecutorService();
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures =

View File

@ -262,8 +262,8 @@ public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
* default timeout duration).
*/
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) {
long timeoutMillis = timeoutMillis();
long startTime;
final long timeoutMillis = timeoutMillis();
final long startTime;
try {
switch (awaitMethod) {
case awaitTimed:
@ -282,7 +282,7 @@ public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
case awaitUntil:
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis());
java.util.Date delayedDate = delayedDate(timeoutMillis);
assertFalse(c.awaitUntil(delayedDate(timeoutMillis)));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
break;

View File

@ -265,8 +265,8 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
* default timeout duration).
*/
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) {
long timeoutMillis = timeoutMillis();
long startTime;
final long timeoutMillis = timeoutMillis();
final long startTime;
try {
switch (awaitMethod) {
case awaitTimed:
@ -285,7 +285,7 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
case awaitUntil:
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis());
java.util.Date delayedDate = delayedDate(timeoutMillis);
assertFalse(c.awaitUntil(delayedDate(timeoutMillis)));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
break;

View File

@ -316,7 +316,7 @@ public class Atomic8Test extends JSR166TestCase {
* result of supplied function
*/
public void testReferenceArrayGetAndUpdate() {
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<>(1);
a.set(0, one);
assertEquals((Integer) 1, a.getAndUpdate(0, Atomic8Test::addInteger17));
assertEquals((Integer) 18, a.getAndUpdate(0, Atomic8Test::addInteger17));
@ -328,7 +328,7 @@ public class Atomic8Test extends JSR166TestCase {
* returns result.
*/
public void testReferenceArrayUpdateAndGet() {
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<>(1);
a.set(0, one);
assertEquals((Integer) 18, a.updateAndGet(0, Atomic8Test::addInteger17));
assertEquals((Integer) 35, a.updateAndGet(0, Atomic8Test::addInteger17));
@ -339,7 +339,7 @@ public class Atomic8Test extends JSR166TestCase {
* with supplied function.
*/
public void testReferenceArrayGetAndAccumulate() {
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<>(1);
a.set(0, one);
assertEquals((Integer) 1, a.getAndAccumulate(0, 2, Atomic8Test::sumInteger));
assertEquals((Integer) 3, a.getAndAccumulate(0, 3, Atomic8Test::sumInteger));
@ -351,7 +351,7 @@ public class Atomic8Test extends JSR166TestCase {
* returns result.
*/
public void testReferenceArrayAccumulateAndGet() {
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<Integer>(1);
AtomicReferenceArray<Integer> a = new AtomicReferenceArray<>(1);
a.set(0, one);
assertEquals((Integer) 7, a.accumulateAndGet(0, 6, Atomic8Test::sumInteger));
assertEquals((Integer) 10, a.accumulateAndGet(0, 3, Atomic8Test::sumInteger));

View File

@ -51,7 +51,7 @@ public class AtomicReferenceArrayTest extends JSR166TestCase {
* constructor creates array of given size with all elements null
*/
public void testConstructor() {
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(SIZE);
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(SIZE);
for (int i = 0; i < SIZE; i++) {
assertNull(aa.get(i));
}
@ -73,7 +73,7 @@ public class AtomicReferenceArrayTest extends JSR166TestCase {
*/
public void testConstructor2() {
Integer[] a = { two, one, three, four, seven };
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(a);
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(a);
assertEquals(a.length, aa.length());
for (int i = 0; i < a.length; i++)
assertEquals(a[i], aa.get(i));
@ -98,7 +98,7 @@ public class AtomicReferenceArrayTest extends JSR166TestCase {
* get and set for out of bound indices throw IndexOutOfBoundsException
*/
public void testIndexing() {
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(SIZE);
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(SIZE);
for (int index : new int[] { -1, SIZE }) {
try {
aa.get(index);
@ -240,7 +240,7 @@ public class AtomicReferenceArrayTest extends JSR166TestCase {
*/
public void testToString() {
Integer[] a = { two, one, three, four, seven };
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(a);
AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(a);
assertEquals(Arrays.toString(a), aa.toString());
}

View File

@ -120,10 +120,10 @@ public class CompletableFutureTest extends JSR166TestCase {
* Returns the "raw" internal exceptional completion of f,
* without any additional wrapping with CompletionException.
*/
<U> Throwable exceptionalCompletion(CompletableFuture<U> f) {
// handle (and whenComplete) can distinguish between "direct"
// and "wrapped" exceptional completion
return f.handle((U u, Throwable t) -> t).join();
Throwable exceptionalCompletion(CompletableFuture<?> f) {
// handle (and whenComplete and exceptionally) can distinguish
// between "direct" and "wrapped" exceptional completion
return f.handle((u, t) -> t).join();
}
void checkCompletedExceptionally(CompletableFuture<?> f,
@ -3559,7 +3559,7 @@ public class CompletableFutureTest extends JSR166TestCase {
*/
public void testCompletedStage() {
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<Throwable>();
AtomicReference<Throwable> r = new AtomicReference<>();
CompletionStage<Integer> f = CompletableFuture.completedStage(1);
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
assertEquals(x.get(), 1);
@ -3661,7 +3661,7 @@ public class CompletableFutureTest extends JSR166TestCase {
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> g = f.minimalCompletionStage();
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<Throwable>();
AtomicReference<Throwable> r = new AtomicReference<>();
checkIncomplete(f);
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
f.complete(1);
@ -3678,7 +3678,7 @@ public class CompletableFutureTest extends JSR166TestCase {
CompletableFuture<Integer> f = new CompletableFuture<>();
CompletionStage<Integer> g = f.minimalCompletionStage();
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<Throwable>();
AtomicReference<Throwable> r = new AtomicReference<>();
g.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
checkIncomplete(f);
CFException ex = new CFException();
@ -3696,7 +3696,7 @@ public class CompletableFutureTest extends JSR166TestCase {
CFException ex = new CFException();
CompletionStage<Integer> f = CompletableFuture.failedStage(ex);
AtomicInteger x = new AtomicInteger(0);
AtomicReference<Throwable> r = new AtomicReference<Throwable>();
AtomicReference<Throwable> r = new AtomicReference<>();
f.whenComplete((v, e) -> {if (e != null) r.set(e); else x.set(v);});
assertEquals(x.get(), 0);
assertEquals(r.get(), ex);

View File

@ -61,7 +61,7 @@ public class ConcurrentHashMapTest extends JSR166TestCase {
* Returns a new map from Integers 1-5 to Strings "A"-"E".
*/
private static ConcurrentHashMap<Integer, String> map5() {
ConcurrentHashMap map = new ConcurrentHashMap<Integer, String>(5);
ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>(5);
assertTrue(map.isEmpty());
map.put(one, "A");
map.put(two, "B");

View File

@ -68,7 +68,7 @@ public class ConcurrentLinkedDequeTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private ConcurrentLinkedDeque<Integer> populatedDeque(int n) {
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<Integer>();
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
assertTrue(q.offer(new Integer(i)));

View File

@ -66,7 +66,7 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<Integer>();
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
assertTrue(q.offer(new Integer(i)));

View File

@ -54,7 +54,7 @@ public class CopyOnWriteArrayListTest extends JSR166TestCase {
public static Test suite() {
class Implementation implements CollectionImplementation {
public Class<?> klazz() { return ArrayList.class; }
public Class<?> klazz() { return CopyOnWriteArrayList.class; }
public List emptyCollection() { return new CopyOnWriteArrayList(); }
public Object makeElement(int i) { return i; }
public boolean isConcurrent() { return true; }
@ -72,7 +72,7 @@ public class CopyOnWriteArrayListTest extends JSR166TestCase {
}
static CopyOnWriteArrayList<Integer> populatedArray(int n) {
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<Integer>();
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<>();
assertTrue(a.isEmpty());
for (int i = 0; i < n; i++)
a.add(i);
@ -82,7 +82,7 @@ public class CopyOnWriteArrayListTest extends JSR166TestCase {
}
static CopyOnWriteArrayList<Integer> populatedArray(Integer[] elements) {
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<Integer>();
CopyOnWriteArrayList<Integer> a = new CopyOnWriteArrayList<>();
assertTrue(a.isEmpty());
for (int i = 0; i < elements.length; i++)
a.add(elements[i]);

View File

@ -53,7 +53,7 @@ public class CopyOnWriteArraySetTest extends JSR166TestCase {
}
static CopyOnWriteArraySet<Integer> populatedSet(int n) {
CopyOnWriteArraySet<Integer> a = new CopyOnWriteArraySet<Integer>();
CopyOnWriteArraySet<Integer> a = new CopyOnWriteArraySet<>();
assertTrue(a.isEmpty());
for (int i = 0; i < n; i++)
a.add(i);
@ -63,7 +63,7 @@ public class CopyOnWriteArraySetTest extends JSR166TestCase {
}
static CopyOnWriteArraySet populatedSet(Integer[] elements) {
CopyOnWriteArraySet<Integer> a = new CopyOnWriteArraySet<Integer>();
CopyOnWriteArraySet<Integer> a = new CopyOnWriteArraySet<>();
assertTrue(a.isEmpty());
for (int i = 0; i < elements.length; i++)
a.add(elements[i]);

View File

@ -238,7 +238,7 @@ public class CountedCompleterTest extends JSR166TestCase {
final AtomicInteger onCompletionN = new AtomicInteger(0);
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0);
final AtomicInteger setRawResultN = new AtomicInteger(0);
final AtomicReference<Object> rawResult = new AtomicReference<Object>(null);
final AtomicReference<Object> rawResult = new AtomicReference<>(null);
int computeN() { return computeN.get(); }
int onCompletionN() { return onCompletionN.get(); }
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); }

View File

@ -79,20 +79,15 @@ public class DelayQueueTest extends JSR166TestCase {
}
/**
* A delayed implementation for testing.
* Most tests use Pseudodelays, where delays are all elapsed
* A fake Delayed implementation for testing.
* Most tests use PDelays, where delays are all elapsed
* (so, no blocking solely for delays) but are still ordered
*/
static class PDelay implements Delayed {
int pseudodelay;
PDelay(int i) { pseudodelay = i; }
public int compareTo(PDelay other) {
int a = this.pseudodelay;
int b = other.pseudodelay;
return (a < b) ? -1 : (a > b) ? 1 : 0;
}
final int pseudodelay;
PDelay(int pseudodelay) { this.pseudodelay = pseudodelay; }
public int compareTo(Delayed y) {
return compareTo((PDelay)y);
return Integer.compare(this.pseudodelay, ((PDelay)y).pseudodelay);
}
public boolean equals(Object other) {
return (other instanceof PDelay) &&
@ -112,20 +107,13 @@ public class DelayQueueTest extends JSR166TestCase {
* Delayed implementation that actually delays
*/
static class NanoDelay implements Delayed {
long trigger;
final long trigger;
NanoDelay(long i) {
trigger = System.nanoTime() + i;
}
public int compareTo(NanoDelay y) {
long i = trigger;
long j = y.trigger;
if (i < j) return -1;
if (i > j) return 1;
return 0;
}
public int compareTo(Delayed y) {
return compareTo((NanoDelay)y);
return Long.compare(trigger, ((NanoDelay)y).trigger);
}
public boolean equals(Object other) {
@ -155,7 +143,7 @@ public class DelayQueueTest extends JSR166TestCase {
* PDelays 0 ... n - 1.
*/
private DelayQueue<PDelay> populatedQueue(int n) {
DelayQueue<PDelay> q = new DelayQueue<PDelay>();
DelayQueue<PDelay> q = new DelayQueue<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
assertTrue(q.offer(new PDelay(i)));
@ -713,7 +701,7 @@ public class DelayQueueTest extends JSR166TestCase {
* Delayed actions do not occur until their delay elapses
*/
public void testDelay() throws InterruptedException {
DelayQueue<NanoDelay> q = new DelayQueue<NanoDelay>();
DelayQueue<NanoDelay> q = new DelayQueue<>();
for (int i = 0; i < SIZE; ++i)
q.add(new NanoDelay(1000000L * (SIZE - i)));

View File

@ -308,7 +308,7 @@ public class ExecutorsTest extends JSR166TestCase {
delay(LONG_DELAY_MS);
}};
List<Thread> threads = new ArrayList<Thread>();
List<Thread> threads = new ArrayList<>();
for (final ExecutorService executor : executors) {
threads.add(newStartedThread(new CheckedRunnable() {
public void realRun() {

View File

@ -658,7 +658,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAny3() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(null);
try {
e.invokeAny(l);
@ -674,7 +674,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
CountDownLatch latch = new CountDownLatch(1);
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -691,7 +691,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAny5() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -708,7 +708,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAny6() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -747,7 +747,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAll3() throws InterruptedException {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -764,7 +764,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAll4() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -783,7 +783,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testInvokeAll5() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -812,7 +812,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -842,7 +842,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
CountDownLatch latch = new CountDownLatch(1);
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -860,7 +860,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -879,7 +879,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -907,7 +907,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testTimedInvokeAllNullTimeUnit() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -935,7 +935,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testTimedInvokeAll3() throws InterruptedException {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -951,7 +951,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testTimedInvokeAll4() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures
= e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
@ -971,7 +971,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
public void testTimedInvokeAll5() throws Throwable {
ForkJoinPool e = new ForkJoinPool(1);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures

View File

@ -71,7 +71,7 @@ public class LinkedListTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private LinkedList<Integer> populatedQueue(int n) {
LinkedList<Integer> q = new LinkedList<Integer>();
LinkedList<Integer> q = new LinkedList<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)
assertTrue(q.offer(new Integer(i)));

View File

@ -209,7 +209,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
* all elements successfully put are contained
*/
public void testPut() {
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.size());
q.put(i);
@ -442,7 +442,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
*/
public void testContainsAll() {
LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
LinkedTransferQueue<Integer> p = new LinkedTransferQueue<Integer>();
LinkedTransferQueue<Integer> p = new LinkedTransferQueue<>();
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
@ -571,8 +571,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
* iterator ordering is FIFO
*/
public void testIteratorOrdering() {
final LinkedTransferQueue<Integer> q
= new LinkedTransferQueue<Integer>();
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
q.add(one);
q.add(two);
@ -794,8 +793,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
* is returned by this associated poll.
*/
public void testTransfer2() throws InterruptedException {
final LinkedTransferQueue<Integer> q
= new LinkedTransferQueue<Integer>();
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
final CountDownLatch threadStarted = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
@ -817,8 +815,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
* transfer waits until a poll occurs, and then transfers in fifo order
*/
public void testTransfer3() throws InterruptedException {
final LinkedTransferQueue<Integer> q
= new LinkedTransferQueue<Integer>();
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
Thread first = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
@ -874,8 +871,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
* is returned by this associated take.
*/
public void testTransfer5() throws InterruptedException {
final LinkedTransferQueue<Integer> q
= new LinkedTransferQueue<Integer>();
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
@ -1056,7 +1052,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
}
private LinkedTransferQueue<Integer> populatedQueue(int n) {
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<Integer>();
LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
checkEmpty(q);
for (int i = 0; i < n; i++) {
assertEquals(i, q.size());

View File

@ -329,7 +329,7 @@ public class PhaserTest extends JSR166TestCase {
public void testArrive2() {
final Phaser phaser = new Phaser();
assertEquals(0, phaser.register());
List<Thread> threads = new ArrayList<Thread>();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 10; i++) {
assertEquals(0, phaser.register());
threads.add(newStartedThread(new CheckedRunnable() {
@ -647,7 +647,7 @@ public class PhaserTest extends JSR166TestCase {
public void testAwaitAdvance4() {
final Phaser phaser = new Phaser(4);
final AtomicInteger count = new AtomicInteger(0);
List<Thread> threads = new ArrayList<Thread>();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 4; i++)
threads.add(newStartedThread(new CheckedRunnable() {
public void realRun() {
@ -671,7 +671,7 @@ public class PhaserTest extends JSR166TestCase {
assertEquals(1, phaser.awaitAdvance(phaser.arrive()));
assertEquals(1, phaser.getPhase());
assertEquals(1, phaser.register());
List<Thread> threads = new ArrayList<Thread>();
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 8; i++) {
final CountDownLatch latch = new CountDownLatch(1);
final boolean goesFirst = ((i & 1) == 0);
@ -699,13 +699,13 @@ public class PhaserTest extends JSR166TestCase {
*/
public void testAwaitAdvanceTieredPhaser() throws Exception {
final Phaser parent = new Phaser();
final List<Phaser> zeroPartyChildren = new ArrayList<Phaser>(3);
final List<Phaser> onePartyChildren = new ArrayList<Phaser>(3);
final List<Phaser> zeroPartyChildren = new ArrayList<>(3);
final List<Phaser> onePartyChildren = new ArrayList<>(3);
for (int i = 0; i < 3; i++) {
zeroPartyChildren.add(new Phaser(parent, 0));
onePartyChildren.add(new Phaser(parent, 1));
}
final List<Phaser> phasers = new ArrayList<Phaser>();
final List<Phaser> phasers = new ArrayList<>();
phasers.addAll(zeroPartyChildren);
phasers.addAll(onePartyChildren);
phasers.add(parent);
@ -747,7 +747,7 @@ public class PhaserTest extends JSR166TestCase {
public void testAwaitAdvance6() {
final Phaser phaser = new Phaser(3);
final CountDownLatch pleaseForceTermination = new CountDownLatch(2);
final List<Thread> threads = new ArrayList<Thread>();
final List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 2; i++) {
Runnable r = new CheckedRunnable() {
public void realRun() {
@ -791,7 +791,7 @@ public class PhaserTest extends JSR166TestCase {
final Phaser phaser = new Phaser(1);
final int THREADS = 3;
final CountDownLatch pleaseArrive = new CountDownLatch(THREADS);
final List<Thread> threads = new ArrayList<Thread>();
final List<Thread> threads = new ArrayList<>();
for (int i = 0; i < THREADS; i++)
threads.add(newStartedThread(new CheckedRunnable() {
public void realRun() {

View File

@ -71,7 +71,7 @@ public class PriorityQueueTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private PriorityQueue<Integer> populatedQueue(int n) {
PriorityQueue<Integer> q = new PriorityQueue<Integer>(n);
PriorityQueue<Integer> q = new PriorityQueue<>(n);
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
assertTrue(q.offer(new Integer(i)));

View File

@ -236,7 +236,7 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testUnlock_IMSE() { testUnlock_IMSE(false); }
public void testUnlock_IMSE_fair() { testUnlock_IMSE(true); }
public void testUnlock_IMSE(boolean fair) {
ReentrantLock lock = new ReentrantLock(fair);
final ReentrantLock lock = new ReentrantLock(fair);
try {
lock.unlock();
shouldThrow();
@ -426,11 +426,11 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testTryLock_Timeout_fair() { testTryLock_Timeout(true); }
public void testTryLock_Timeout(boolean fair) {
final PublicReentrantLock lock = new PublicReentrantLock(fair);
final long timeoutMillis = timeoutMillis();
lock.lock();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
long timeoutMillis = 10;
assertFalse(lock.tryLock(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
}});
@ -445,7 +445,7 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testGetHoldCount() { testGetHoldCount(false); }
public void testGetHoldCount_fair() { testGetHoldCount(true); }
public void testGetHoldCount(boolean fair) {
ReentrantLock lock = new ReentrantLock(fair);
final ReentrantLock lock = new ReentrantLock(fair);
for (int i = 1; i <= SIZE; i++) {
lock.lock();
assertEquals(i, lock.getHoldCount());
@ -462,8 +462,8 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testIsLocked() { testIsLocked(false); }
public void testIsLocked_fair() { testIsLocked(true); }
public void testIsLocked(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
try {
final ReentrantLock lock = new ReentrantLock(fair);
assertFalse(lock.isLocked());
lock.lock();
assertTrue(lock.isLocked());
@ -550,18 +550,18 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testAwaitNanos_Timeout() { testAwaitNanos_Timeout(false); }
public void testAwaitNanos_Timeout_fair() { testAwaitNanos_Timeout(true); }
public void testAwaitNanos_Timeout(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
final long timeoutMillis = timeoutMillis();
final long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
lock.lock();
final long startTime = System.nanoTime();
try {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
lock.lock();
long startTime = System.nanoTime();
long timeoutMillis = 10;
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(timeoutNanos);
assertTrue(nanosRemaining <= 0);
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.unlock();
}
/**
@ -570,16 +570,16 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testAwait_Timeout() { testAwait_Timeout(false); }
public void testAwait_Timeout_fair() { testAwait_Timeout(true); }
public void testAwait_Timeout(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
final long timeoutMillis = timeoutMillis();
lock.lock();
final long startTime = System.nanoTime();
try {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
lock.lock();
long startTime = System.nanoTime();
long timeoutMillis = 10;
assertFalse(c.await(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.unlock();
}
/**
@ -588,17 +588,17 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testAwaitUntil_Timeout() { testAwaitUntil_Timeout(false); }
public void testAwaitUntil_Timeout_fair() { testAwaitUntil_Timeout(true); }
public void testAwaitUntil_Timeout(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
lock.lock();
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
final java.util.Date delayedDate = delayedDate(timeoutMillis());
try {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
lock.lock();
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis());
assertFalse(c.awaitUntil(delayedDate));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
lock.unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
lock.unlock();
}
/**
@ -1127,7 +1127,7 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testSerialization() { testSerialization(false); }
public void testSerialization_fair() { testSerialization(true); }
public void testSerialization(boolean fair) {
ReentrantLock lock = new ReentrantLock(fair);
final ReentrantLock lock = new ReentrantLock(fair);
lock.lock();
ReentrantLock clone = serialClone(lock);
@ -1153,10 +1153,10 @@ public class ReentrantLockTest extends JSR166TestCase {
public void testToString() { testToString(false); }
public void testToString_fair() { testToString(true); }
public void testToString(boolean fair) {
ReentrantLock lock = new ReentrantLock(fair);
final ReentrantLock lock = new ReentrantLock(fair);
assertTrue(lock.toString().contains("Unlocked"));
lock.lock();
assertTrue(lock.toString().contains("Locked"));
assertTrue(lock.toString().contains("Locked by"));
lock.unlock();
assertTrue(lock.toString().contains("Unlocked"));
}

View File

@ -258,7 +258,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testGetWriteHoldCount() { testGetWriteHoldCount(false); }
public void testGetWriteHoldCount_fair() { testGetWriteHoldCount(true); }
public void testGetWriteHoldCount(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
for (int i = 1; i <= SIZE; i++) {
lock.writeLock().lock();
assertEquals(i,lock.getWriteHoldCount());
@ -275,7 +275,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testGetHoldCount() { testGetHoldCount(false); }
public void testGetHoldCount_fair() { testGetHoldCount(true); }
public void testGetHoldCount(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
for (int i = 1; i <= SIZE; i++) {
lock.writeLock().lock();
assertEquals(i,lock.writeLock().getHoldCount());
@ -292,7 +292,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testGetReadHoldCount() { testGetReadHoldCount(false); }
public void testGetReadHoldCount_fair() { testGetReadHoldCount(true); }
public void testGetReadHoldCount(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
for (int i = 1; i <= SIZE; i++) {
lock.readLock().lock();
assertEquals(i,lock.getReadHoldCount());
@ -309,7 +309,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testWriteUnlock_IMSE() { testWriteUnlock_IMSE(false); }
public void testWriteUnlock_IMSE_fair() { testWriteUnlock_IMSE(true); }
public void testWriteUnlock_IMSE(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
try {
lock.writeLock().unlock();
shouldThrow();
@ -322,7 +322,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testReadUnlock_IMSE() { testReadUnlock_IMSE(false); }
public void testReadUnlock_IMSE_fair() { testReadUnlock_IMSE(true); }
public void testReadUnlock_IMSE(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
try {
lock.readLock().unlock();
shouldThrow();
@ -815,11 +815,11 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testWriteTryLock_Timeout(boolean fair) {
final PublicReentrantReadWriteLock lock =
new PublicReentrantReadWriteLock(fair);
final long timeoutMillis = timeoutMillis();
lock.writeLock().lock();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
long timeoutMillis = 10;
assertFalse(lock.writeLock().tryLock(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
}});
@ -839,7 +839,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
long timeoutMillis = 10;
long timeoutMillis = timeoutMillis();
assertFalse(lock.readLock().tryLock(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
}});
@ -951,19 +951,18 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testAwaitNanos_Timeout() { testAwaitNanos_Timeout(false); }
public void testAwaitNanos_Timeout_fair() { testAwaitNanos_Timeout(true); }
public void testAwaitNanos_Timeout(boolean fair) {
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
final long timeoutMillis = timeoutMillis();
lock.writeLock().lock();
final long startTime = System.nanoTime();
final long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
try {
final ReentrantReadWriteLock lock =
new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
lock.writeLock().lock();
long startTime = System.nanoTime();
long timeoutMillis = 10;
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(timeoutNanos);
assertTrue(nanosRemaining <= 0);
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.writeLock().unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.writeLock().unlock();
}
/**
@ -972,17 +971,16 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testAwait_Timeout() { testAwait_Timeout(false); }
public void testAwait_Timeout_fair() { testAwait_Timeout(true); }
public void testAwait_Timeout(boolean fair) {
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
final long timeoutMillis = timeoutMillis();
lock.writeLock().lock();
final long startTime = System.nanoTime();
try {
final ReentrantReadWriteLock lock =
new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
lock.writeLock().lock();
long startTime = System.nanoTime();
long timeoutMillis = 10;
assertFalse(c.await(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.writeLock().unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.writeLock().unlock();
}
/**
@ -991,18 +989,17 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testAwaitUntil_Timeout() { testAwaitUntil_Timeout(false); }
public void testAwaitUntil_Timeout_fair() { testAwaitUntil_Timeout(true); }
public void testAwaitUntil_Timeout(boolean fair) {
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
lock.writeLock().lock();
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
final java.util.Date delayedDate = delayedDate(timeoutMillis());
try {
final ReentrantReadWriteLock lock =
new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
lock.writeLock().lock();
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis());
assertFalse(c.awaitUntil(delayedDate));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
lock.writeLock().unlock();
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
lock.writeLock().unlock();
}
/**
@ -1258,7 +1255,7 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testSerialization() { testSerialization(false); }
public void testSerialization_fair() { testSerialization(true); }
public void testSerialization(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
lock.writeLock().lock();
lock.readLock().lock();
@ -1660,14 +1657,20 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testToString() { testToString(false); }
public void testToString_fair() { testToString(true); }
public void testToString(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
assertTrue(lock.toString().contains("Write locks = 0"));
assertTrue(lock.toString().contains("Read locks = 0"));
lock.writeLock().lock();
assertTrue(lock.toString().contains("Write locks = 1"));
assertTrue(lock.toString().contains("Read locks = 0"));
lock.writeLock().lock();
assertTrue(lock.toString().contains("Write locks = 2"));
assertTrue(lock.toString().contains("Read locks = 0"));
lock.writeLock().unlock();
lock.writeLock().unlock();
lock.readLock().lock();
assertTrue(lock.toString().contains("Write locks = 0"));
assertTrue(lock.toString().contains("Read locks = 1"));
lock.readLock().lock();
assertTrue(lock.toString().contains("Write locks = 0"));
assertTrue(lock.toString().contains("Read locks = 2"));
@ -1679,11 +1682,16 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testReadLockToString() { testReadLockToString(false); }
public void testReadLockToString_fair() { testReadLockToString(true); }
public void testReadLockToString(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
assertTrue(lock.readLock().toString().contains("Read locks = 0"));
lock.readLock().lock();
assertTrue(lock.readLock().toString().contains("Read locks = 1"));
lock.readLock().lock();
assertTrue(lock.readLock().toString().contains("Read locks = 2"));
lock.readLock().unlock();
assertTrue(lock.readLock().toString().contains("Read locks = 1"));
lock.readLock().unlock();
assertTrue(lock.readLock().toString().contains("Read locks = 0"));
}
/**
@ -1692,10 +1700,10 @@ public class ReentrantReadWriteLockTest extends JSR166TestCase {
public void testWriteLockToString() { testWriteLockToString(false); }
public void testWriteLockToString_fair() { testWriteLockToString(true); }
public void testWriteLockToString(boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
assertTrue(lock.writeLock().toString().contains("Unlocked"));
lock.writeLock().lock();
assertTrue(lock.writeLock().toString().contains("Locked"));
assertTrue(lock.writeLock().toString().contains("Locked by"));
lock.writeLock().unlock();
assertTrue(lock.writeLock().toString().contains("Unlocked"));
}

View File

@ -967,7 +967,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
final CountDownLatch latch = new CountDownLatch(1);
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -984,7 +984,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testInvokeAny4() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -1001,7 +1001,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testInvokeAny5() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -1039,7 +1039,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testInvokeAll3() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1055,7 +1055,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testInvokeAll4() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -1074,7 +1074,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testInvokeAll5() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -1103,7 +1103,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testTimedInvokeAnyNullTimeUnit() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -1132,7 +1132,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
CountDownLatch latch = new CountDownLatch(1);
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1150,7 +1150,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1169,7 +1169,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1197,7 +1197,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testTimedInvokeAllNullTimeUnit() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -1223,7 +1223,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testTimedInvokeAll3() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1239,7 +1239,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testTimedInvokeAll4() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures =
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
@ -1259,7 +1259,7 @@ public class ScheduledExecutorSubclassTest extends JSR166TestCase {
public void testTimedInvokeAll5() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures =

View File

@ -915,7 +915,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
CountDownLatch latch = new CountDownLatch(1);
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -932,7 +932,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testInvokeAny4() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -949,7 +949,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testInvokeAny5() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -987,7 +987,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testInvokeAll3() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1003,7 +1003,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testInvokeAll4() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -1022,7 +1022,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testInvokeAll5() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -1051,7 +1051,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testTimedInvokeAnyNullTimeUnit() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -1080,7 +1080,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
CountDownLatch latch = new CountDownLatch(1);
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1098,7 +1098,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1117,7 +1117,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1145,7 +1145,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testTimedInvokeAllNullTimeUnit() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -1172,7 +1172,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testTimedInvokeAll3() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1188,7 +1188,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testTimedInvokeAll4() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures =
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
@ -1208,7 +1208,7 @@ public class ScheduledExecutorTest extends JSR166TestCase {
public void testTimedInvokeAll5() throws Exception {
final ExecutorService e = new ScheduledThreadPoolExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures =

View File

@ -173,7 +173,7 @@ public class SubmissionPublisherTest extends JSR166TestCase {
* defaultExecutor
*/
public void testConstructor1() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>();
SubmissionPublisher<Integer> p = new SubmissionPublisher<>();
checkInitialState(p);
assertEquals(p.getMaxBufferCapacity(), Flow.defaultBufferSize());
Executor e = p.getExecutor(), c = ForkJoinPool.commonPool();
@ -189,7 +189,7 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testConstructor2() {
Executor e = Executors.newFixedThreadPool(1);
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(e, 8);
SubmissionPublisher<Integer> p = new SubmissionPublisher<>(e, 8);
checkInitialState(p);
assertSame(p.getExecutor(), e);
assertEquals(8, p.getMaxBufferCapacity());
@ -471,9 +471,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testThrowOnNextHandler() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>
(basicExecutor, 8,
(s, e) -> calls.getAndIncrement());
SubmissionPublisher<Integer> p = new SubmissionPublisher<>(
basicExecutor, 8, (s, e) -> calls.getAndIncrement());
TestSubscriber s1 = new TestSubscriber();
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s1);
@ -654,8 +653,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
* submit eventually issues requested items when buffer capacity is 1
*/
public void testCap1Submit() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 1);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 1);
TestSubscriber s1 = new TestSubscriber();
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s1);
@ -733,8 +732,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
* offer reports drops if saturated
*/
public void testDroppedOffer() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
@ -762,8 +761,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
@ -790,8 +789,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testRecoveredHandledDroppedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
@ -871,8 +870,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
* Timed offer reports drops if saturated
*/
public void testDroppedTimedOffer() {
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
@ -903,8 +902,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testHandledDroppedTimedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();
@ -933,8 +932,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
*/
public void testRecoveredHandledDroppedTimedOffer() {
AtomicInteger calls = new AtomicInteger();
SubmissionPublisher<Integer> p = new SubmissionPublisher<Integer>(
basicExecutor, 4);
SubmissionPublisher<Integer> p
= new SubmissionPublisher<>(basicExecutor, 4);
TestSubscriber s1 = new TestSubscriber();
s1.request = false;
TestSubscriber s2 = new TestSubscriber();

View File

@ -428,8 +428,7 @@ public class SynchronousQueueTest extends JSR166TestCase {
public void testToArray2() { testToArray2(false); }
public void testToArray2_fair() { testToArray2(true); }
public void testToArray2(boolean fair) {
final SynchronousQueue<Integer> q
= new SynchronousQueue<Integer>(fair);
final SynchronousQueue<Integer> q = new SynchronousQueue<>(fair);
Integer[] a;
a = new Integer[0];

View File

@ -678,7 +678,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
*/
public void testGetQueue() throws InterruptedException {
final CountDownLatch done = new CountDownLatch(1);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new CustomTPE(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -687,7 +687,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
final CountDownLatch threadStarted = new CountDownLatch(1);
FutureTask[] tasks = new FutureTask[5];
for (int i = 0; i < tasks.length; i++) {
Callable task = new CheckedCallable<Boolean>() {
Callable<Boolean> task = new CheckedCallable<Boolean>() {
public Boolean realCall() throws InterruptedException {
threadStarted.countDown();
assertSame(q, p.getQueue());
@ -710,7 +710,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
*/
public void testRemove() throws InterruptedException {
final CountDownLatch done = new CountDownLatch(1);
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new CustomTPE(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -745,7 +745,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
public void testPurge() throws InterruptedException {
final CountDownLatch threadStarted = new CountDownLatch(1);
final CountDownLatch done = new CountDownLatch(1);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new CustomTPE(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -753,7 +753,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
try (PoolCleaner cleaner = cleaner(p, done)) {
FutureTask[] tasks = new FutureTask[5];
for (int i = 0; i < tasks.length; i++) {
Callable task = new CheckedCallable<Boolean>() {
Callable<Boolean> task = new CheckedCallable<Boolean>() {
public Boolean realCall() throws InterruptedException {
threadStarted.countDown();
await(done);
@ -1532,7 +1532,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1552,7 +1552,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -1572,7 +1572,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -1619,7 +1619,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1638,7 +1638,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -1660,7 +1660,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -1695,7 +1695,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -1731,7 +1731,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1752,7 +1752,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1774,7 +1774,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1808,7 +1808,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -1841,7 +1841,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1860,7 +1860,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures =
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
@ -1883,7 +1883,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures =

View File

@ -563,7 +563,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
*/
public void testGetQueue() throws InterruptedException {
final CountDownLatch done = new CountDownLatch(1);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -595,7 +595,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
*/
public void testRemove() throws InterruptedException {
final CountDownLatch done = new CountDownLatch(1);
BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -630,7 +630,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
public void testPurge() throws InterruptedException {
final CountDownLatch threadStarted = new CountDownLatch(1);
final CountDownLatch done = new CountDownLatch(1);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
final BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(10);
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 1,
LONG_DELAY_MS, MILLISECONDS,
@ -1534,7 +1534,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1554,7 +1554,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
@ -1574,7 +1574,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l);
@ -1621,7 +1621,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1640,7 +1640,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
@ -1662,7 +1662,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l);
@ -1697,7 +1697,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAny(l, MEDIUM_DELAY_MS, null);
@ -1733,7 +1733,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
@ -1754,7 +1754,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1776,7 +1776,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
long startTime = System.nanoTime();
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
@ -1810,7 +1810,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, MEDIUM_DELAY_MS, null);
@ -1843,7 +1843,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
@ -1862,7 +1862,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
List<Future<String>> futures =
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
@ -1885,7 +1885,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures =

View File

@ -70,7 +70,7 @@ public class TreeSetTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private TreeSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<Integer>();
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
assertTrue(q.add(new Integer(i)));

View File

@ -61,7 +61,7 @@ public class TreeSubSetTest extends JSR166TestCase {
* Integers 0 ... n - 1.
*/
private NavigableSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<Integer>();
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)