Skip to content
Permalink
Browse files
8234131: Miscellaneous changes imported from jsr166 CVS 2021-01
8257671: ThreadPoolExecutor.Discard*Policy: rejected tasks are not cancelled

Reviewed-by: alanb, prappo, dl
  • Loading branch information
Martin Buchholz committed Jan 9, 2021
1 parent 63e3bd7 commit 270014ab4ec4588a0f662e0b9bbdfb3feaf4e723
Showing with 273 additions and 207 deletions.
  1. +2 −2 src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java
  2. +1 −1 src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java
  3. +3 −5 src/java.base/share/classes/java/util/concurrent/CountDownLatch.java
  4. +3 −1 src/java.base/share/classes/java/util/concurrent/CyclicBarrier.java
  5. +3 −3 src/java.base/share/classes/java/util/concurrent/Exchanger.java
  6. +1 −1 src/java.base/share/classes/java/util/concurrent/ExecutorService.java
  7. +21 −18 src/java.base/share/classes/java/util/concurrent/Future.java
  8. +2 −2 src/java.base/share/classes/java/util/concurrent/Phaser.java
  9. +4 −2 src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java
  10. +1 −1 src/java.base/share/classes/java/util/concurrent/Semaphore.java
  11. +66 −19 src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java
  12. +29 −9 src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java
  13. +1 −2 src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java
  14. +1 −1 src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
  15. +3 −2 src/java.base/share/classes/java/util/concurrent/atomic/DoubleAccumulator.java
  16. +3 −2 src/java.base/share/classes/java/util/concurrent/atomic/DoubleAdder.java
  17. +3 −2 src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java
  18. +3 −2 src/java.base/share/classes/java/util/concurrent/atomic/LongAdder.java
  19. +25 −28 src/java.base/share/classes/java/util/concurrent/atomic/Striped64.java
  20. +1 −1 src/java.base/share/classes/java/util/concurrent/atomic/package-info.java
  21. +2 −2 src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
  22. +3 −3 src/java.base/share/classes/java/util/concurrent/locks/ReentrantLock.java
  23. +2 −2 src/java.base/share/classes/java/util/concurrent/locks/ReentrantReadWriteLock.java
  24. +2 −2 src/java.base/share/classes/java/util/concurrent/locks/StampedLock.java
  25. +0 −1 test/jdk/java/util/Collection/IteratorMicroBenchmark.java
  26. +20 −19 test/jdk/java/util/concurrent/ExecutorService/Invoke.java
  27. +1 −1 test/jdk/java/util/concurrent/tck/ArrayBlockingQueueTest.java
  28. +1 −1 test/jdk/java/util/concurrent/tck/ArrayDequeTest.java
  29. +1 −1 test/jdk/java/util/concurrent/tck/ArrayListTest.java
  30. +0 −3 test/jdk/java/util/concurrent/tck/Collection8Test.java
  31. +3 −16 test/jdk/java/util/concurrent/tck/CompletableFutureTest.java
  32. +0 −1 test/jdk/java/util/concurrent/tck/ConcurrentLinkedDequeTest.java
  33. +17 −12 test/jdk/java/util/concurrent/tck/ExecutorsTest.java
  34. +3 −3 test/jdk/java/util/concurrent/tck/ForkJoinPoolTest.java
  35. +2 −1 test/jdk/java/util/concurrent/tck/JSR166TestCase.java
  36. +8 −8 test/jdk/java/util/concurrent/tck/RecursiveTaskTest.java
  37. +15 −12 test/jdk/java/util/concurrent/tck/SplittableRandomTest.java
  38. +7 −2 test/jdk/java/util/concurrent/tck/StampedLockTest.java
  39. +1 −1 test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java
  40. +1 −1 test/jdk/java/util/concurrent/tck/SynchronousQueueTest.java
  41. +8 −11 test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java
@@ -54,13 +54,13 @@
* to return {@code RunnableFuture} implementations other than
* {@code FutureTask}.
*
* <p><b>Extension example</b>. Here is a sketch of a class
* <p><b>Extension example.</b> Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use
* a {@code CustomTask} class instead of the default {@code FutureTask}:
* <pre> {@code
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
*
* static class CustomTask<V> implements RunnableFuture<V> {...}
* static class CustomTask<V> implements RunnableFuture<V> { ... }
*
* protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
* return new CustomTask<V>(c);
@@ -69,7 +69,7 @@
* perform some action upon state updates.
*
* <pre> {@code
* class Handler { void handle(); ... }
* class Handler { void handle() { ... } }
*
* class X {
* private final CopyOnWriteArraySet<Handler> handlers
@@ -118,7 +118,7 @@
* class Driver2 { // ...
* void main() throws InterruptedException {
* CountDownLatch doneSignal = new CountDownLatch(N);
* Executor e = ...
* Executor e = ...;
*
* for (int i = 0; i < N; ++i) // create and start threads
* e.execute(new WorkerRunnable(doneSignal, i));
@@ -135,10 +135,8 @@
* this.i = i;
* }
* public void run() {
* try {
* doWork(i);
* doneSignal.countDown();
* } catch (InterruptedException ex) {} // return;
* doWork();
* doneSignal.countDown();
* }
*
* void doWork() { ... }
@@ -94,7 +94,9 @@
*
* // wait until done
* for (Thread thread : threads)
* thread.join();
* try {
* thread.join();
* } catch (InterruptedException ex) { }
* }
* }}</pre>
*
@@ -57,8 +57,8 @@
* <pre> {@code
* class FillAndEmpty {
* Exchanger<DataBuffer> exchanger = new Exchanger<>();
* DataBuffer initialEmptyBuffer = ... a made-up type
* DataBuffer initialFullBuffer = ...
* DataBuffer initialEmptyBuffer = ...; // a made-up type
* DataBuffer initialFullBuffer = ...;
*
* class FillingLoop implements Runnable {
* public void run() {
@@ -69,7 +69,7 @@
* if (currentBuffer.isFull())
* currentBuffer = exchanger.exchange(currentBuffer);
* }
* } catch (InterruptedException ex) { ... handle ... }
* } catch (InterruptedException ex) { ... handle ...}
* }
* }
*
@@ -117,7 +117,7 @@
* if (!pool.awaitTermination(60, TimeUnit.SECONDS))
* System.err.println("Pool did not terminate");
* }
* } catch (InterruptedException ie) {
* } catch (InterruptedException ex) {
* // (Re-)Cancel if current thread also interrupted
* pool.shutdownNow();
* // Preserve interrupt status
@@ -56,8 +56,8 @@
* <pre> {@code
* interface ArchiveSearcher { String search(String target); }
* class App {
* ExecutorService executor = ...
* ArchiveSearcher searcher = ...
* ExecutorService executor = ...;
* ArchiveSearcher searcher = ...;
* void showSearch(String target) throws InterruptedException {
* Callable<String> task = () -> searcher.search(target);
* Future<String> future = executor.submit(task);
@@ -88,25 +88,28 @@
public interface Future<V> {

/**
* Attempts to cancel execution of this task. This attempt will
* fail if the task has already completed, has already been cancelled,
* or could not be cancelled for some other reason. If successful,
* and this task has not started when {@code cancel} is called,
* this task should never run. If the task has already started,
* then the {@code mayInterruptIfRunning} parameter determines
* whether the thread executing this task should be interrupted in
* an attempt to stop the task.
* Attempts to cancel execution of this task. This method has no
* effect if the task is already completed or cancelled, or could
* not be cancelled for some other reason. Otherwise, if this
* task has not started when {@code cancel} is called, this task
* should never run. If the task has already started, then the
* {@code mayInterruptIfRunning} parameter determines whether the
* thread executing this task (when known by the implementation)
* is interrupted in an attempt to stop the task.
*
* <p>After this method returns, subsequent calls to {@link #isDone} will
* always return {@code true}. Subsequent calls to {@link #isCancelled}
* will always return {@code true} if this method returned {@code true}.
* <p>The return value from this method does not necessarily
* indicate whether the task is now cancelled; use {@link
* #isCancelled}.
*
* @param mayInterruptIfRunning {@code true} if the thread executing this
* task should be interrupted; otherwise, in-progress tasks are allowed
* to complete
* @param mayInterruptIfRunning {@code true} if the thread
* executing this task should be interrupted (if the thread is
* known to the implementation); otherwise, in-progress tasks are
* allowed to complete
* @return {@code false} if the task could not be cancelled,
* typically because it has already completed normally;
* {@code true} otherwise
* typically because it has already completed; {@code true}
* otherwise. If two or more threads cause a task to be cancelled,
* then at least one of them returns {@code true}. Implementations
* may provide stronger guarantees.
*/
boolean cancel(boolean mayInterruptIfRunning);

@@ -245,7 +245,7 @@
* be appropriate for extremely small per-phase task bodies (thus
* high rates), or up to hundreds for extremely large ones.
*
* <p><b>Implementation notes</b>: This implementation restricts the
* <p><b>Implementation notes:</b> This implementation restricts the
* maximum number of parties to 65535. Attempts to register additional
* parties result in {@code IllegalStateException}. However, you can and
* should create tiered phasers to accommodate arbitrarily large sets
@@ -919,7 +919,7 @@ public boolean isTerminated() {
* <pre> {@code
* Phaser phaser = new Phaser() {
* protected boolean onAdvance(int phase, int parties) { return false; }
* }}</pre>
* };}</pre>
*
* @param phase the current phase number on entry to this method,
* before this phaser is advanced
@@ -87,7 +87,7 @@
* <pre> {@code
* class FIFOEntry<E extends Comparable<? super E>>
* implements Comparable<FIFOEntry<E>> {
* static final AtomicLong seq = new AtomicLong(0);
* static final AtomicLong seq = new AtomicLong();
* final long seqNum;
* final E entry;
* public FIFOEntry(E entry) {
@@ -290,7 +290,9 @@ private void tryGrow(Object[] array, int oldCap) {
if (allocationSpinLock == 0 &&
ALLOCATIONSPINLOCK.compareAndSet(this, 0, 1)) {
try {
int growth = oldCap < 64 ? oldCap + 2 : oldCap >> 1;
int growth = (oldCap < 64)
? (oldCap + 2) // grow faster if small
: (oldCap >> 1);
int newCap = ArraysSupport.newLength(oldCap, 1, growth);
if (queue == array)
newArray = new Object[newCap];
@@ -66,7 +66,7 @@
*
* // Not a particularly efficient data structure; just for demo
*
* protected Object[] items = ... whatever kinds of items being managed
* protected Object[] items = ...; // whatever kinds of items being managed
* protected boolean[] used = new boolean[MAX_AVAILABLE];
*
* protected synchronized Object getNextAvailableItem() {
Loading

1 comment on commit 270014a

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 270014a Jan 9, 2021

Please sign in to comment.