< prev index next >

src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Print this page




  96  * tuning, and monitoring fork/join applications. Also, method
  97  * {@link #toString} returns indications of pool state in a
  98  * convenient form for informal monitoring.
  99  *
 100  * <p>As is the case with other ExecutorServices, there are three
 101  * main task execution methods summarized in the following table.
 102  * These are designed to be used primarily by clients not already
 103  * engaged in fork/join computations in the current pool.  The main
 104  * forms of these methods accept instances of {@code ForkJoinTask},
 105  * but overloaded forms also allow mixed execution of plain {@code
 106  * Runnable}- or {@code Callable}- based activities as well.  However,
 107  * tasks that are already executing in a pool should normally instead
 108  * use the within-computation forms listed in the table unless using
 109  * async event-style tasks that are not usually joined, in which case
 110  * there is little difference among choice of methods.
 111  *
 112  * <table class="plain">
 113  * <caption>Summary of task execution methods</caption>
 114  *  <tr>
 115  *    <td></td>
 116  *    <td style="text-align:center"> <b>Call from non-fork/join clients</b></td>
 117  *    <td style="text-align:center"> <b>Call from within fork/join computations</b></td>
 118  *  </tr>
 119  *  <tr>
 120  *    <td> <b>Arrange async execution</b></td>
 121  *    <td> {@link #execute(ForkJoinTask)}</td>
 122  *    <td> {@link ForkJoinTask#fork}</td>
 123  *  </tr>
 124  *  <tr>
 125  *    <td> <b>Await and obtain result</b></td>
 126  *    <td> {@link #invoke(ForkJoinTask)}</td>
 127  *    <td> {@link ForkJoinTask#invoke}</td>
 128  *  </tr>
 129  *  <tr>
 130  *    <td> <b>Arrange exec and obtain Future</b></td>
 131  *    <td> {@link #submit(ForkJoinTask)}</td>
 132  *    <td> {@link ForkJoinTask#fork} (ForkJoinTasks <em>are</em> Futures)</td>
 133  *  </tr>
 134  * </table>
 135  *
 136  * <p>The parameters used to construct the common pool may be controlled by
 137  * setting the following {@linkplain System#getProperty system properties}:
 138  * <ul>
 139  * <li>{@code java.util.concurrent.ForkJoinPool.common.parallelism}
 140  * - the parallelism level, a non-negative integer
 141  * <li>{@code java.util.concurrent.ForkJoinPool.common.threadFactory}
 142  * - the class name of a {@link ForkJoinWorkerThreadFactory}.
 143  * The {@linkplain ClassLoader#getSystemClassLoader() system class loader}
 144  * is used to load this class.
 145  * <li>{@code java.util.concurrent.ForkJoinPool.common.exceptionHandler}
 146  * - the class name of a {@link UncaughtExceptionHandler}.
 147  * The {@linkplain ClassLoader#getSystemClassLoader() system class loader}
 148  * is used to load this class.
 149  * <li>{@code java.util.concurrent.ForkJoinPool.common.maximumSpares}
 150  * - the maximum number of allowed extra threads to maintain target




  96  * tuning, and monitoring fork/join applications. Also, method
  97  * {@link #toString} returns indications of pool state in a
  98  * convenient form for informal monitoring.
  99  *
 100  * <p>As is the case with other ExecutorServices, there are three
 101  * main task execution methods summarized in the following table.
 102  * These are designed to be used primarily by clients not already
 103  * engaged in fork/join computations in the current pool.  The main
 104  * forms of these methods accept instances of {@code ForkJoinTask},
 105  * but overloaded forms also allow mixed execution of plain {@code
 106  * Runnable}- or {@code Callable}- based activities as well.  However,
 107  * tasks that are already executing in a pool should normally instead
 108  * use the within-computation forms listed in the table unless using
 109  * async event-style tasks that are not usually joined, in which case
 110  * there is little difference among choice of methods.
 111  *
 112  * <table class="plain">
 113  * <caption>Summary of task execution methods</caption>
 114  *  <tr>
 115  *    <td></td>
 116  *    <th scope="col"> Call from non-fork/join clients</th>
 117  *    <th scope="col"> Call from within fork/join computations</th>
 118  *  </tr>
 119  *  <tr>
 120  *    <th scope="row" style="text-align:left"> Arrange async execution</th>
 121  *    <td> {@link #execute(ForkJoinTask)}</td>
 122  *    <td> {@link ForkJoinTask#fork}</td>
 123  *  </tr>
 124  *  <tr>
 125  *    <th scope="row" style="text-align:left"> Await and obtain result</th>
 126  *    <td> {@link #invoke(ForkJoinTask)}</td>
 127  *    <td> {@link ForkJoinTask#invoke}</td>
 128  *  </tr>
 129  *  <tr>
 130  *    <th scope="row" style="text-align:left"> Arrange exec and obtain Future</th>
 131  *    <td> {@link #submit(ForkJoinTask)}</td>
 132  *    <td> {@link ForkJoinTask#fork} (ForkJoinTasks <em>are</em> Futures)</td>
 133  *  </tr>
 134  * </table>
 135  *
 136  * <p>The parameters used to construct the common pool may be controlled by
 137  * setting the following {@linkplain System#getProperty system properties}:
 138  * <ul>
 139  * <li>{@code java.util.concurrent.ForkJoinPool.common.parallelism}
 140  * - the parallelism level, a non-negative integer
 141  * <li>{@code java.util.concurrent.ForkJoinPool.common.threadFactory}
 142  * - the class name of a {@link ForkJoinWorkerThreadFactory}.
 143  * The {@linkplain ClassLoader#getSystemClassLoader() system class loader}
 144  * is used to load this class.
 145  * <li>{@code java.util.concurrent.ForkJoinPool.common.exceptionHandler}
 146  * - the class name of a {@link UncaughtExceptionHandler}.
 147  * The {@linkplain ClassLoader#getSystemClassLoader() system class loader}
 148  * is used to load this class.
 149  * <li>{@code java.util.concurrent.ForkJoinPool.common.maximumSpares}
 150  * - the maximum number of allowed extra threads to maintain target


< prev index next >