8165919: Miscellaneous changes imported from jsr166 CVS 2016-09-21
Reviewed-by: martin, chegar, shade
This commit is contained in:
parent
edc7565f51
commit
c7cf1788ed
@ -1191,7 +1191,7 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
* Default idle timeout value (in milliseconds) for the thread
|
* Default idle timeout value (in milliseconds) for the thread
|
||||||
* triggering quiescence to park waiting for new work
|
* triggering quiescence to park waiting for new work
|
||||||
*/
|
*/
|
||||||
private static final long DEFAULT_KEEPALIVE = 60000L;
|
private static final long DEFAULT_KEEPALIVE = 60_000L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undershoot tolerance for idle timeouts
|
* Undershoot tolerance for idle timeouts
|
||||||
@ -2303,7 +2303,6 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
long ms = Math.max(unit.toMillis(keepAliveTime), TIMEOUT_SLOP);
|
long ms = Math.max(unit.toMillis(keepAliveTime), TIMEOUT_SLOP);
|
||||||
|
|
||||||
String prefix = "ForkJoinPool-" + nextPoolId() + "-worker-";
|
|
||||||
int corep = Math.min(Math.max(corePoolSize, parallelism), MAX_CAP);
|
int corep = Math.min(Math.max(corePoolSize, parallelism), MAX_CAP);
|
||||||
long c = ((((long)(-corep) << TC_SHIFT) & TC_MASK) |
|
long c = ((((long)(-corep) << TC_SHIFT) & TC_MASK) |
|
||||||
(((long)(-parallelism) << RC_SHIFT) & RC_MASK));
|
(((long)(-parallelism) << RC_SHIFT) & RC_MASK));
|
||||||
@ -2315,8 +2314,8 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
|
n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
|
||||||
n = (n + 1) << 1; // power of two, including space for submission queues
|
n = (n + 1) << 1; // power of two, including space for submission queues
|
||||||
|
|
||||||
|
this.workerNamePrefix = "ForkJoinPool-" + nextPoolId() + "-worker-";
|
||||||
this.workQueues = new WorkQueue[n];
|
this.workQueues = new WorkQueue[n];
|
||||||
this.workerNamePrefix = prefix;
|
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.ueh = handler;
|
this.ueh = handler;
|
||||||
this.saturate = saturate;
|
this.saturate = saturate;
|
||||||
@ -2327,11 +2326,19 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
checkPermission();
|
checkPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object newInstanceFromSystemProperty(String property)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
String className = System.getProperty(property);
|
||||||
|
return (className == null)
|
||||||
|
? null
|
||||||
|
: ClassLoader.getSystemClassLoader().loadClass(className)
|
||||||
|
.getConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for common pool using parameters possibly
|
* Constructor for common pool using parameters possibly
|
||||||
* overridden by system properties
|
* overridden by system properties
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // Class.newInstance
|
|
||||||
private ForkJoinPool(byte forCommonPoolOnly) {
|
private ForkJoinPool(byte forCommonPoolOnly) {
|
||||||
int parallelism = -1;
|
int parallelism = -1;
|
||||||
ForkJoinWorkerThreadFactory fac = null;
|
ForkJoinWorkerThreadFactory fac = null;
|
||||||
@ -2339,18 +2346,12 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
try { // ignore exceptions in accessing/parsing properties
|
try { // ignore exceptions in accessing/parsing properties
|
||||||
String pp = System.getProperty
|
String pp = System.getProperty
|
||||||
("java.util.concurrent.ForkJoinPool.common.parallelism");
|
("java.util.concurrent.ForkJoinPool.common.parallelism");
|
||||||
String fp = System.getProperty
|
|
||||||
("java.util.concurrent.ForkJoinPool.common.threadFactory");
|
|
||||||
String hp = System.getProperty
|
|
||||||
("java.util.concurrent.ForkJoinPool.common.exceptionHandler");
|
|
||||||
if (pp != null)
|
if (pp != null)
|
||||||
parallelism = Integer.parseInt(pp);
|
parallelism = Integer.parseInt(pp);
|
||||||
if (fp != null)
|
fac = (ForkJoinWorkerThreadFactory) newInstanceFromSystemProperty(
|
||||||
fac = ((ForkJoinWorkerThreadFactory)ClassLoader.
|
"java.util.concurrent.ForkJoinPool.common.threadFactory");
|
||||||
getSystemClassLoader().loadClass(fp).newInstance());
|
handler = (UncaughtExceptionHandler) newInstanceFromSystemProperty(
|
||||||
if (hp != null)
|
"java.util.concurrent.ForkJoinPool.common.exceptionHandler");
|
||||||
handler = ((UncaughtExceptionHandler)ClassLoader.
|
|
||||||
getSystemClassLoader().loadClass(hp).newInstance());
|
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2373,8 +2374,8 @@ public class ForkJoinPool extends AbstractExecutorService {
|
|||||||
n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
|
n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16;
|
||||||
n = (n + 1) << 1;
|
n = (n + 1) << 1;
|
||||||
|
|
||||||
this.workQueues = new WorkQueue[n];
|
|
||||||
this.workerNamePrefix = "ForkJoinPool.commonPool-worker-";
|
this.workerNamePrefix = "ForkJoinPool.commonPool-worker-";
|
||||||
|
this.workQueues = new WorkQueue[n];
|
||||||
this.factory = fac;
|
this.factory = fac;
|
||||||
this.ueh = handler;
|
this.ueh = handler;
|
||||||
this.saturate = null;
|
this.saturate = null;
|
||||||
|
@ -35,6 +35,9 @@
|
|||||||
|
|
||||||
package java.util.concurrent.atomic;
|
package java.util.concurrent.atomic;
|
||||||
|
|
||||||
|
import static java.lang.Double.doubleToRawLongBits;
|
||||||
|
import static java.lang.Double.longBitsToDouble;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.function.DoubleBinaryOperator;
|
import java.util.function.DoubleBinaryOperator;
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
|
|||||||
public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction,
|
public DoubleAccumulator(DoubleBinaryOperator accumulatorFunction,
|
||||||
double identity) {
|
double identity) {
|
||||||
this.function = accumulatorFunction;
|
this.function = accumulatorFunction;
|
||||||
base = this.identity = Double.doubleToRawLongBits(identity);
|
base = this.identity = doubleToRawLongBits(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,18 +104,19 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public void accumulate(double x) {
|
public void accumulate(double x) {
|
||||||
Cell[] as; long b, v, r; int m; Cell a;
|
Cell[] as; long b, v, r; int m; Cell a;
|
||||||
if ((as = cells) != null ||
|
if ((as = cells) != null
|
||||||
(r = Double.doubleToRawLongBits
|
|| ((r = doubleToRawLongBits
|
||||||
(function.applyAsDouble
|
(function.applyAsDouble(longBitsToDouble(b = base), x))) != b
|
||||||
(Double.longBitsToDouble(b = base), x))) != b && !casBase(b, r)) {
|
&& !casBase(b, r))) {
|
||||||
boolean uncontended = true;
|
boolean uncontended = true;
|
||||||
if (as == null || (m = as.length - 1) < 0 ||
|
if (as == null
|
||||||
(a = as[getProbe() & m]) == null ||
|
|| (m = as.length - 1) < 0
|
||||||
!(uncontended =
|
|| (a = as[getProbe() & m]) == null
|
||||||
(r = Double.doubleToRawLongBits
|
|| !(uncontended =
|
||||||
(function.applyAsDouble
|
((r = doubleToRawLongBits
|
||||||
(Double.longBitsToDouble(v = a.value), x))) == v ||
|
(function.applyAsDouble
|
||||||
a.cas(v, r)))
|
(longBitsToDouble(v = a.value), x))) == v)
|
||||||
|
|| a.cas(v, r)))
|
||||||
doubleAccumulate(x, function, uncontended);
|
doubleAccumulate(x, function, uncontended);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,12 +132,12 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public double get() {
|
public double get() {
|
||||||
Cell[] as = cells;
|
Cell[] as = cells;
|
||||||
double result = Double.longBitsToDouble(base);
|
double result = longBitsToDouble(base);
|
||||||
if (as != null) {
|
if (as != null) {
|
||||||
for (Cell a : as)
|
for (Cell a : as)
|
||||||
if (a != null)
|
if (a != null)
|
||||||
result = function.applyAsDouble
|
result = function.applyAsDouble
|
||||||
(result, Double.longBitsToDouble(a.value));
|
(result, longBitsToDouble(a.value));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -168,12 +172,12 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public double getThenReset() {
|
public double getThenReset() {
|
||||||
Cell[] as = cells;
|
Cell[] as = cells;
|
||||||
double result = Double.longBitsToDouble(base);
|
double result = longBitsToDouble(base);
|
||||||
base = identity;
|
base = identity;
|
||||||
if (as != null) {
|
if (as != null) {
|
||||||
for (Cell a : as) {
|
for (Cell a : as) {
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
double v = Double.longBitsToDouble(a.value);
|
double v = longBitsToDouble(a.value);
|
||||||
a.reset(identity);
|
a.reset(identity);
|
||||||
result = function.applyAsDouble(result, v);
|
result = function.applyAsDouble(result, v);
|
||||||
}
|
}
|
||||||
@ -267,9 +271,9 @@ public class DoubleAccumulator extends Striped64 implements Serializable {
|
|||||||
* held by this proxy
|
* held by this proxy
|
||||||
*/
|
*/
|
||||||
private Object readResolve() {
|
private Object readResolve() {
|
||||||
double d = Double.longBitsToDouble(identity);
|
double d = longBitsToDouble(identity);
|
||||||
DoubleAccumulator a = new DoubleAccumulator(function, d);
|
DoubleAccumulator a = new DoubleAccumulator(function, d);
|
||||||
a.base = Double.doubleToRawLongBits(value);
|
a.base = doubleToRawLongBits(value);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,14 +103,16 @@ public class LongAccumulator extends Striped64 implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public void accumulate(long x) {
|
public void accumulate(long x) {
|
||||||
Cell[] as; long b, v, r; int m; Cell a;
|
Cell[] as; long b, v, r; int m; Cell a;
|
||||||
if ((as = cells) != null ||
|
if ((as = cells) != null
|
||||||
(r = function.applyAsLong(b = base, x)) != b && !casBase(b, r)) {
|
|| ((r = function.applyAsLong(b = base, x)) != b
|
||||||
|
&& !casBase(b, r))) {
|
||||||
boolean uncontended = true;
|
boolean uncontended = true;
|
||||||
if (as == null || (m = as.length - 1) < 0 ||
|
if (as == null
|
||||||
(a = as[getProbe() & m]) == null ||
|
|| (m = as.length - 1) < 0
|
||||||
!(uncontended =
|
|| (a = as[getProbe() & m]) == null
|
||||||
(r = function.applyAsLong(v = a.value, x)) == v ||
|
|| !(uncontended =
|
||||||
a.cas(v, r)))
|
(r = function.applyAsLong(v = a.value, x)) == v
|
||||||
|
|| a.cas(v, r)))
|
||||||
longAccumulate(x, function, uncontended);
|
longAccumulate(x, function, uncontended);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,6 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@ -41,10 +40,8 @@ import org.testng.annotations.Test;
|
|||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
|
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertSame;
|
|
||||||
|
|
||||||
public class EmptyNavigableMap {
|
public class EmptyNavigableMap {
|
||||||
|
|
||||||
|
@ -41,10 +41,9 @@ import org.testng.annotations.Test;
|
|||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
|
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertSame;
|
import static org.testng.Assert.assertSame;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
public class EmptyNavigableSet {
|
public class EmptyNavigableSet {
|
||||||
|
|
||||||
|
@ -28,8 +28,14 @@
|
|||||||
* @author Martin Buchholz
|
* @author Martin Buchholz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayDeque;
|
||||||
import java.util.concurrent.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
|
||||||
public class ChorusLine {
|
public class ChorusLine {
|
||||||
private interface Tweaker {
|
private interface Tweaker {
|
||||||
|
@ -28,7 +28,11 @@
|
|||||||
* @author Martin Buchholz
|
* @author Martin Buchholz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
public class ForgetMeNot {
|
public class ForgetMeNot {
|
||||||
private static void checkQ(PriorityQueue<Integer> q, Integer...elts) {
|
private static void checkQ(PriorityQueue<Integer> q, Integer...elts) {
|
||||||
|
@ -37,7 +37,13 @@
|
|||||||
* @summary Checks that a priority queue returns elements in sorted order across various operations
|
* @summary Checks that a priority queue returns elements in sorted order across various operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
public class PriorityQueueSort {
|
public class PriorityQueueSort {
|
||||||
|
|
||||||
|
@ -28,8 +28,17 @@
|
|||||||
* @author Martin Buchholz
|
* @author Martin Buchholz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayDeque;
|
||||||
import java.util.concurrent.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedTransferQueue;
|
||||||
|
|
||||||
public class RemoveContains {
|
public class RemoveContains {
|
||||||
static volatile int passed = 0, failed = 0;
|
static volatile int passed = 0, failed = 0;
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import static java.util.concurrent.Executors.defaultThreadFactory;
|
import static java.util.concurrent.Executors.defaultThreadFactory;
|
||||||
import static java.util.concurrent.Executors.newFixedThreadPool;
|
|
||||||
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
|
|
||||||
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
@ -303,7 +303,7 @@ public class AtomicIntegerArrayTest extends JSR166TestCase {
|
|||||||
|
|
||||||
class Counter extends CheckedRunnable {
|
class Counter extends CheckedRunnable {
|
||||||
final AtomicIntegerArray aa;
|
final AtomicIntegerArray aa;
|
||||||
volatile int counts;
|
int decs;
|
||||||
Counter(AtomicIntegerArray a) { aa = a; }
|
Counter(AtomicIntegerArray a) { aa = a; }
|
||||||
public void realRun() {
|
public void realRun() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -314,7 +314,7 @@ public class AtomicIntegerArrayTest extends JSR166TestCase {
|
|||||||
if (v != 0) {
|
if (v != 0) {
|
||||||
done = false;
|
done = false;
|
||||||
if (aa.compareAndSet(i, v, v - 1))
|
if (aa.compareAndSet(i, v, v - 1))
|
||||||
++counts;
|
decs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
@ -334,13 +334,11 @@ public class AtomicIntegerArrayTest extends JSR166TestCase {
|
|||||||
aa.set(i, countdown);
|
aa.set(i, countdown);
|
||||||
Counter c1 = new Counter(aa);
|
Counter c1 = new Counter(aa);
|
||||||
Counter c2 = new Counter(aa);
|
Counter c2 = new Counter(aa);
|
||||||
Thread t1 = new Thread(c1);
|
Thread t1 = newStartedThread(c1);
|
||||||
Thread t2 = new Thread(c2);
|
Thread t2 = newStartedThread(c2);
|
||||||
t1.start();
|
|
||||||
t2.start();
|
|
||||||
t1.join();
|
t1.join();
|
||||||
t2.join();
|
t2.join();
|
||||||
assertEquals(c1.counts+c2.counts, SIZE * countdown);
|
assertEquals(c1.decs + c2.decs, SIZE * countdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -302,7 +302,7 @@ public class AtomicLongArrayTest extends JSR166TestCase {
|
|||||||
|
|
||||||
class Counter extends CheckedRunnable {
|
class Counter extends CheckedRunnable {
|
||||||
final AtomicLongArray aa;
|
final AtomicLongArray aa;
|
||||||
volatile long counts;
|
int decs;
|
||||||
Counter(AtomicLongArray a) { aa = a; }
|
Counter(AtomicLongArray a) { aa = a; }
|
||||||
public void realRun() {
|
public void realRun() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -313,7 +313,7 @@ public class AtomicLongArrayTest extends JSR166TestCase {
|
|||||||
if (v != 0) {
|
if (v != 0) {
|
||||||
done = false;
|
done = false;
|
||||||
if (aa.compareAndSet(i, v, v - 1))
|
if (aa.compareAndSet(i, v, v - 1))
|
||||||
++counts;
|
decs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
@ -333,13 +333,11 @@ public class AtomicLongArrayTest extends JSR166TestCase {
|
|||||||
aa.set(i, countdown);
|
aa.set(i, countdown);
|
||||||
Counter c1 = new Counter(aa);
|
Counter c1 = new Counter(aa);
|
||||||
Counter c2 = new Counter(aa);
|
Counter c2 = new Counter(aa);
|
||||||
Thread t1 = new Thread(c1);
|
Thread t1 = newStartedThread(c1);
|
||||||
Thread t2 = new Thread(c2);
|
Thread t2 = newStartedThread(c2);
|
||||||
t1.start();
|
|
||||||
t2.start();
|
|
||||||
t1.join();
|
t1.join();
|
||||||
t2.join();
|
t2.join();
|
||||||
assertEquals(c1.counts+c2.counts, SIZE * countdown);
|
assertEquals(c1.decs + c2.decs, SIZE * countdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1024,7 +1024,7 @@ public class ConcurrentSkipListMapTest extends JSR166TestCase {
|
|||||||
|
|
||||||
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
|
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
|
||||||
NavigableMap<Integer, Integer> result =
|
NavigableMap<Integer, Integer> result =
|
||||||
(NavigableMap<Integer, Integer>) cl.newInstance();
|
(NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
assertFalse(result.keySet().iterator().hasNext());
|
assertFalse(result.keySet().iterator().hasNext());
|
||||||
return result;
|
return result;
|
||||||
|
@ -725,7 +725,8 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NavigableSet<Integer> newSet(Class cl) throws Exception {
|
static NavigableSet<Integer> newSet(Class cl) throws Exception {
|
||||||
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
|
NavigableSet<Integer> result =
|
||||||
|
(NavigableSet<Integer>) cl.getConstructor().newInstance();
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
assertFalse(result.iterator().hasNext());
|
assertFalse(result.iterator().hasNext());
|
||||||
return result;
|
return result;
|
||||||
|
@ -40,6 +40,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
@ -52,11 +53,6 @@ public class CyclicBarrierTest extends JSR166TestCase {
|
|||||||
return new TestSuite(CyclicBarrierTest.class);
|
return new TestSuite(CyclicBarrierTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private volatile int countAction;
|
|
||||||
private class MyAction implements Runnable {
|
|
||||||
public void run() { ++countAction; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spin-waits till the number of waiters == numberOfWaiters.
|
* Spin-waits till the number of waiters == numberOfWaiters.
|
||||||
*/
|
*/
|
||||||
@ -114,14 +110,16 @@ public class CyclicBarrierTest extends JSR166TestCase {
|
|||||||
* The supplied barrier action is run at barrier
|
* The supplied barrier action is run at barrier
|
||||||
*/
|
*/
|
||||||
public void testBarrierAction() throws Exception {
|
public void testBarrierAction() throws Exception {
|
||||||
countAction = 0;
|
final AtomicInteger count = new AtomicInteger(0);
|
||||||
CyclicBarrier b = new CyclicBarrier(1, new MyAction());
|
final Runnable incCount = new Runnable() { public void run() {
|
||||||
|
count.getAndIncrement(); }};
|
||||||
|
CyclicBarrier b = new CyclicBarrier(1, incCount);
|
||||||
assertEquals(1, b.getParties());
|
assertEquals(1, b.getParties());
|
||||||
assertEquals(0, b.getNumberWaiting());
|
assertEquals(0, b.getNumberWaiting());
|
||||||
b.await();
|
b.await();
|
||||||
b.await();
|
b.await();
|
||||||
assertEquals(0, b.getNumberWaiting());
|
assertEquals(0, b.getNumberWaiting());
|
||||||
assertEquals(2, countAction);
|
assertEquals(2, count.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,10 +121,8 @@ public class DelayQueueTest extends JSR166TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return equals((NanoDelay)other);
|
return (other instanceof NanoDelay) &&
|
||||||
}
|
this.trigger == ((NanoDelay)other).trigger;
|
||||||
public boolean equals(NanoDelay other) {
|
|
||||||
return other.trigger == trigger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// suppress [overrides] javac warning
|
// suppress [overrides] javac warning
|
||||||
|
@ -51,6 +51,7 @@ import java.util.concurrent.Future;
|
|||||||
import java.util.concurrent.RecursiveTask;
|
import java.util.concurrent.RecursiveTask;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
@ -84,13 +85,6 @@ public class ForkJoinPoolTest extends JSR166TestCase {
|
|||||||
|
|
||||||
// Some classes to test extension and factory methods
|
// Some classes to test extension and factory methods
|
||||||
|
|
||||||
static class MyHandler implements Thread.UncaughtExceptionHandler {
|
|
||||||
volatile int catches = 0;
|
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
|
||||||
++catches;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class MyError extends Error {}
|
static class MyError extends Error {}
|
||||||
|
|
||||||
// to test handlers
|
// to test handlers
|
||||||
@ -101,9 +95,9 @@ public class ForkJoinPoolTest extends JSR166TestCase {
|
|||||||
|
|
||||||
static class FailingThreadFactory
|
static class FailingThreadFactory
|
||||||
implements ForkJoinPool.ForkJoinWorkerThreadFactory {
|
implements ForkJoinPool.ForkJoinWorkerThreadFactory {
|
||||||
volatile int calls = 0;
|
final AtomicInteger calls = new AtomicInteger(0);
|
||||||
public ForkJoinWorkerThread newThread(ForkJoinPool p) {
|
public ForkJoinWorkerThread newThread(ForkJoinPool p) {
|
||||||
if (++calls > 1) return null;
|
if (calls.incrementAndGet() > 1) return null;
|
||||||
return new FailingFJWSubclass(p);
|
return new FailingFJWSubclass(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,15 +537,14 @@ public class ScheduledExecutorTest extends JSR166TestCase {
|
|||||||
* isShutdown is false before shutdown, true after
|
* isShutdown is false before shutdown, true after
|
||||||
*/
|
*/
|
||||||
public void testIsShutdown() {
|
public void testIsShutdown() {
|
||||||
|
|
||||||
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
|
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
|
||||||
try {
|
assertFalse(p.isShutdown());
|
||||||
assertFalse(p.isShutdown());
|
try (PoolCleaner cleaner = cleaner(p)) {
|
||||||
|
try {
|
||||||
|
p.shutdown();
|
||||||
|
assertTrue(p.isShutdown());
|
||||||
|
} catch (SecurityException ok) {}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
try { p.shutdown(); } catch (SecurityException ok) { return; }
|
|
||||||
}
|
|
||||||
assertTrue(p.isShutdown());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -829,7 +829,7 @@ public class TreeMapTest extends JSR166TestCase {
|
|||||||
|
|
||||||
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
|
static NavigableMap<Integer, Integer> newMap(Class cl) throws Exception {
|
||||||
NavigableMap<Integer, Integer> result
|
NavigableMap<Integer, Integer> result
|
||||||
= (NavigableMap<Integer, Integer>) cl.newInstance();
|
= (NavigableMap<Integer, Integer>) cl.getConstructor().newInstance();
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
assertFalse(result.keySet().iterator().hasNext());
|
assertFalse(result.keySet().iterator().hasNext());
|
||||||
return result;
|
return result;
|
||||||
|
@ -722,7 +722,8 @@ public class TreeSetTest extends JSR166TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NavigableSet<Integer> newSet(Class cl) throws Exception {
|
static NavigableSet<Integer> newSet(Class cl) throws Exception {
|
||||||
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance();
|
NavigableSet<Integer> result =
|
||||||
|
(NavigableSet<Integer>) cl.getConstructor().newInstance();
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
assertFalse(result.iterator().hasNext());
|
assertFalse(result.iterator().hasNext());
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user