Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8297648

j.u.concurrent updates for JDK 20

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 20
    • core-libs
    • None
    • source
    • minimal
    • New methods.
    • Java API
    • SE

      Summary

      Update java.util.concurrent.ForkJoinPool with new methods that provide finer grain control on submitting tasks.

      Problem

      ForkJoinPool has submission queues for tasks submitted to the pool by "external clients", and task queues owned by threads in the pool. If a ForkJoinTask submits a task then it will always be pushed to the current thread's task queue, there is no way for it to add a task to a submission queue. For FIFO usage, and virtual threads specifically, it would useful to have finer control when submitting tasks.

      Solution

      Add ForkJoinPool.externalSubmit to adds a task to a submission queue.

      Add ForkJoinWorkerThread. getQueuedTaskCount to return the number of tasks in the local task queue.

      Specification

      Add java.util.concurrent.ForkJoinPool.externalSubmit

          /**
           * 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)  { .. }

      Update java.util.concurrent.ForkJoinPool.submit(ForkJoinTask) to add:

           * @implSpec
           * This method is equivalent to {@link #externalSubmit(ForkJoinTask)}
           * when called from a thread that is not in this pool.

      Update java.util.concurrent.ForkJoinPool.lazySubmit(ForkJoinTask ) to document the exceptions that it can throw. These were missed when the method was added in Java 19.

           * @throws NullPointerException if the task is null
           * @throws RejectedExecutionException if the task cannot be
           *         scheduled for execution

      Add java.util.concurrent.ForkJoinWorkerThread.getQueuedTaskCount

          /**
           * {@return a (non-negative) estimate of the number of tasks in the
           * thread's queue}
           *
           * @since 20
           * @see ForkJoinPool#getQueuedTaskCount()
           */
          public int getQueuedTaskCount() { .. }

            alanb Alan Bateman
            alanb Alan Bateman
            Doug Lea, Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: