8297495: j.u.concurrent updates for JDK 20

Reviewed-by: jpai
This commit is contained in:
Alan Bateman 2022-12-05 15:20:16 +00:00
parent 328845926d
commit 19d849884b
4 changed files with 276 additions and 4 deletions

View file

@ -2852,6 +2852,10 @@ public class ForkJoinPool extends AbstractExecutorService {
/**
* Submits a ForkJoinTask for execution.
*
* @implSpec
* This method is equivalent to {@link #externalSubmit(ForkJoinTask)}
* when called from a thread that is not in this pool.
*
* @param task the task to submit
* @param <T> the type of the task's result
* @return the task
@ -2898,6 +2902,31 @@ public class ForkJoinPool extends AbstractExecutorService {
// Added mainly for possible use in Loom
/**
* Submits the given task as if submitted from a non-{@code ForkJoinTask}
* client. The task is added to a scheduling queue for submissions to the
* pool even when called from a thread in the pool.
*
* @implSpec
* This method is equivalent to {@link #submit(ForkJoinTask)} when called
* from a thread that is not in this pool.
*
* @return the task
* @param task the task to submit
* @param <T> the type of the task's result
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
* @since 20
*/
public <T> ForkJoinTask<T> externalSubmit(ForkJoinTask<T> task) {
U.storeStoreFence(); // ensure safely publishable
task.markPoolSubmission();
WorkQueue q = submissionQueue(true);
q.push(task, this, true);
return task;
}
/**
* Submits the given task without guaranteeing that it will
* eventually execute in the absence of available active threads.
@ -2909,6 +2938,9 @@ public class ForkJoinPool extends AbstractExecutorService {
* @param task the task
* @param <T> the type of the task's result
* @return the task
* @throws NullPointerException if the task is null
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
* @since 19
*/
public <T> ForkJoinTask<T> lazySubmit(ForkJoinTask<T> task) {
@ -3267,6 +3299,7 @@ public class ForkJoinPool extends AbstractExecutorService {
* granularities.
*
* @return the number of queued tasks
* @see ForkJoinWorkerThread#getQueuedTaskCount()
*/
public long getQueuedTaskCount() {
WorkQueue[] qs; WorkQueue q;

View file

@ -138,6 +138,17 @@ public class ForkJoinWorkerThread extends Thread {
return workQueue.getPoolIndex();
}
/**
* {@return a (non-negative) estimate of the number of tasks in the
* thread's queue}
*
* @since 20
* @see ForkJoinPool#getQueuedTaskCount()
*/
public int getQueuedTaskCount() {
return workQueue.queueSize();
}
/**
* Initializes internal state after construction but before
* processing any tasks. If you override this method, you must