28 |
|
* most tasks spawn other subtasks (as do most ForkJoinTasks), as well |
29 |
|
* as the mixed execution of some plain Runnable- or Callable- based |
30 |
|
* activities along with ForkJoinTasks. When setting |
31 |
< |
* {@code setAsyncMode}, a ForkJoinPools may also be appropriate for |
31 |
> |
* <tt>setAsyncMode</tt>, a ForkJoinPools may also be appropriate for |
32 |
|
* use with fine-grained tasks that are never joined. Otherwise, other |
33 |
|
* ExecutorService implementations are typically more appropriate |
34 |
|
* choices. |
38 |
|
* adding, suspending, or resuming threads, even if some tasks are |
39 |
|
* waiting to join others. However, no such adjustments are performed |
40 |
|
* in the face of blocked IO or other unmanaged synchronization. The |
41 |
< |
* nested {@code ManagedBlocker} interface enables extension of |
41 |
> |
* nested <code>ManagedBlocker</code> interface enables extension of |
42 |
|
* the kinds of synchronization accommodated. The target parallelism |
43 |
< |
* level may also be changed dynamically ({@code setParallelism}) |
43 |
> |
* level may also be changed dynamically (<code>setParallelism</code>) |
44 |
|
* and thread construction can be limited using methods |
45 |
< |
* {@code setMaximumPoolSize} and/or |
46 |
< |
* {@code setMaintainsParallelism}. |
45 |
> |
* <code>setMaximumPoolSize</code> and/or |
46 |
> |
* <code>setMaintainsParallelism</code>. |
47 |
|
* |
48 |
|
* <p>In addition to execution and lifecycle control methods, this |
49 |
|
* class provides status check methods (for example |
50 |
< |
* {@code getStealCount}) that are intended to aid in developing, |
50 |
> |
* <code>getStealCount</code>) that are intended to aid in developing, |
51 |
|
* tuning, and monitoring fork/join applications. Also, method |
52 |
< |
* {@code toString} returns indications of pool state in a |
52 |
> |
* <code>toString</code> returns indications of pool state in a |
53 |
|
* convenient form for informal monitoring. |
54 |
|
* |
55 |
|
* <p><b>Implementation notes</b>: This implementation restricts the |
81 |
|
* Returns a new worker thread operating in the given pool. |
82 |
|
* |
83 |
|
* @param pool the pool this thread works in |
84 |
< |
* @throws NullPointerException if pool is null |
84 |
> |
* @throws NullPointerException if pool is null; |
85 |
|
*/ |
86 |
|
public ForkJoinWorkerThread newThread(ForkJoinPool pool); |
87 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
|
* The uncaught exception handler used when any worker |
156 |
< |
* abruptly terminates |
156 |
> |
* abrupty terminates |
157 |
|
*/ |
158 |
|
private Thread.UncaughtExceptionHandler ueh; |
159 |
|
|
216 |
|
* threads, packed into one int to ensure consistent snapshot when |
217 |
|
* making decisions about creating and suspending spare |
218 |
|
* threads. Updated only by CAS. Note: CASes in |
219 |
< |
* updateRunningCount and preJoin running active count is in low |
220 |
< |
* word, so need to be modified if this changes |
219 |
> |
* updateRunningCount and preJoin assume that running active count |
220 |
> |
* is in low word, so need to be modified if this changes |
221 |
|
*/ |
222 |
|
private volatile int workerCounts; |
223 |
|
|
226 |
|
private static int workerCountsFor(int t, int r) { return (t << 16) + r; } |
227 |
|
|
228 |
|
/** |
229 |
< |
* Adds delta (which may be negative) to running count. This must |
229 |
> |
* Add delta (which may be negative) to running count. This must |
230 |
|
* be called before (with negative arg) and after (with positive) |
231 |
< |
* any managed synchronization (i.e., mainly, joins). |
231 |
> |
* any managed synchronization (i.e., mainly, joins) |
232 |
|
* @param delta the number to add |
233 |
|
*/ |
234 |
|
final void updateRunningCount(int delta) { |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
< |
* Adds delta (which may be negative) to both total and running |
240 |
> |
* Add delta (which may be negative) to both total and running |
241 |
|
* count. This must be called upon creation and termination of |
242 |
|
* worker threads. |
243 |
|
* @param delta the number to add |
273 |
|
/** |
274 |
|
* Try incrementing active count; fail on contention. Called by |
275 |
|
* workers before/during executing tasks. |
276 |
< |
* @return true on success |
276 |
> |
* @return true on success; |
277 |
|
*/ |
278 |
|
final boolean tryIncrementActiveCount() { |
279 |
|
int c = runControl; |
281 |
|
} |
282 |
|
|
283 |
|
/** |
284 |
< |
* Tries decrementing active count; fails on contention. |
285 |
< |
* Possibly triggers termination on success. |
284 |
> |
* Try decrementing active count; fail on contention. |
285 |
> |
* Possibly trigger termination on success |
286 |
|
* Called by workers when they can't find tasks. |
287 |
|
* @return true on success |
288 |
|
*/ |
297 |
|
} |
298 |
|
|
299 |
|
/** |
300 |
< |
* Returns true if argument represents zero active count and |
300 |
> |
* Return true if argument represents zero active count and |
301 |
|
* nonzero runstate, which is the triggering condition for |
302 |
|
* terminating on shutdown. |
303 |
|
*/ |
333 |
|
* @throws SecurityException if a security manager exists and |
334 |
|
* the caller is not permitted to modify threads |
335 |
|
* because it does not hold {@link |
336 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
336 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
337 |
|
*/ |
338 |
|
public ForkJoinPool() { |
339 |
|
this(Runtime.getRuntime().availableProcessors(), |
341 |
|
} |
342 |
|
|
343 |
|
/** |
344 |
< |
* Creates a ForkJoinPool with the indicated parallelism level |
344 |
> |
* Creates a ForkJoinPool with the indicated parellelism level |
345 |
|
* threads, and using the default ForkJoinWorkerThreadFactory, |
346 |
|
* @param parallelism the number of worker threads |
347 |
|
* @throws IllegalArgumentException if parallelism less than or |
349 |
|
* @throws SecurityException if a security manager exists and |
350 |
|
* the caller is not permitted to modify threads |
351 |
|
* because it does not hold {@link |
352 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
352 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
353 |
|
*/ |
354 |
|
public ForkJoinPool(int parallelism) { |
355 |
|
this(parallelism, defaultForkJoinWorkerThreadFactory); |
364 |
|
* @throws SecurityException if a security manager exists and |
365 |
|
* the caller is not permitted to modify threads |
366 |
|
* because it does not hold {@link |
367 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
367 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
368 |
|
*/ |
369 |
|
public ForkJoinPool(ForkJoinWorkerThreadFactory factory) { |
370 |
|
this(Runtime.getRuntime().availableProcessors(), factory); |
376 |
|
* @param parallelism the targeted number of worker threads |
377 |
|
* @param factory the factory for creating new threads |
378 |
|
* @throws IllegalArgumentException if parallelism less than or |
379 |
< |
* equal to zero, or greater than implementation limit |
379 |
> |
* equal to zero, or greater than implementation limit. |
380 |
|
* @throws NullPointerException if factory is null |
381 |
|
* @throws SecurityException if a security manager exists and |
382 |
|
* the caller is not permitted to modify threads |
383 |
|
* because it does not hold {@link |
384 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
384 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
385 |
|
*/ |
386 |
|
public ForkJoinPool(int parallelism, ForkJoinWorkerThreadFactory factory) { |
387 |
|
if (parallelism <= 0 || parallelism > MAX_THREADS) |
421 |
|
} |
422 |
|
|
423 |
|
/** |
424 |
< |
* Returns a good size for worker array given pool size. |
424 |
> |
* Return a good size for worker array given pool size. |
425 |
|
* Currently requires size to be a power of two. |
426 |
|
*/ |
427 |
|
private static int arraySizeFor(int ps) { |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
< |
* Creates or resizes array if necessary to hold newLength. |
433 |
< |
* Call only under exclusion or lock. |
432 |
> |
* Create or resize array if necessary to hold newLength. |
433 |
> |
* Call only under exclusion |
434 |
|
* @return the array |
435 |
|
*/ |
436 |
|
private ForkJoinWorkerThread[] ensureWorkerArrayCapacity(int newLength) { |
689 |
|
* @throws SecurityException if a security manager exists and |
690 |
|
* the caller is not permitted to modify threads |
691 |
|
* because it does not hold {@link |
692 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
692 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
693 |
|
*/ |
694 |
|
public Thread.UncaughtExceptionHandler |
695 |
|
setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler h) { |
716 |
|
|
717 |
|
|
718 |
|
/** |
719 |
< |
* Sets the target parallelism level of this pool. |
719 |
> |
* Sets the target paralleism level of this pool. |
720 |
|
* @param parallelism the target parallelism |
721 |
|
* @throws IllegalArgumentException if parallelism less than or |
722 |
< |
* equal to zero or greater than maximum size bounds |
722 |
> |
* equal to zero or greater than maximum size bounds. |
723 |
|
* @throws SecurityException if a security manager exists and |
724 |
|
* the caller is not permitted to modify threads |
725 |
|
* because it does not hold {@link |
726 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
726 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
727 |
|
*/ |
728 |
|
public void setParallelism(int parallelism) { |
729 |
|
checkPermission(); |
758 |
|
/** |
759 |
|
* Returns the number of worker threads that have started but not |
760 |
|
* yet terminated. This result returned by this method may differ |
761 |
< |
* from {@code getParallelism} when threads are created to |
761 |
> |
* from <code>getParallelism</code> when threads are created to |
762 |
|
* maintain parallelism when others are cooperatively blocked. |
763 |
|
* |
764 |
|
* @return the number of worker threads |
782 |
|
* Setting this value has no effect on current pool size. It |
783 |
|
* controls construction of new threads. |
784 |
|
* @throws IllegalArgumentException if negative or greater then |
785 |
< |
* internal implementation limit |
785 |
> |
* internal implementation limit. |
786 |
|
*/ |
787 |
|
public void setMaximumPoolSize(int newMax) { |
788 |
|
if (newMax < 0 || newMax > MAX_THREADS) |
819 |
|
* worker threads only process asynchronous tasks. This method is |
820 |
|
* designed to be invoked only when pool is quiescent, and |
821 |
|
* typically only before any tasks are submitted. The effects of |
822 |
< |
* invocations at other times may be unpredictable. |
822 |
> |
* invocations at ather times may be unpredictable. |
823 |
|
* |
824 |
|
* @param async if true, use locally FIFO scheduling |
825 |
< |
* @return the previous mode |
825 |
> |
* @return the previous mode. |
826 |
|
*/ |
827 |
|
public boolean setAsyncMode(boolean async) { |
828 |
|
boolean oldMode = locallyFifo; |
840 |
|
|
841 |
|
/** |
842 |
|
* Returns true if this pool uses local first-in-first-out |
843 |
< |
* scheduling mode for forked tasks that are never joined. |
843 |
> |
* scheduling mode for forked tasks that are never joined. |
844 |
|
* |
845 |
< |
* @return true if this pool uses async mode |
845 |
> |
* @return true if this pool uses async mode. |
846 |
|
*/ |
847 |
|
public boolean getAsyncMode() { |
848 |
|
return locallyFifo; |
863 |
|
* Returns an estimate of the number of threads that are currently |
864 |
|
* stealing or executing tasks. This method may overestimate the |
865 |
|
* number of active threads. |
866 |
< |
* @return the number of active threads |
866 |
> |
* @return the number of active threads. |
867 |
|
*/ |
868 |
|
public int getActiveThreadCount() { |
869 |
|
return activeCountOf(runControl); |
873 |
|
* Returns an estimate of the number of threads that are currently |
874 |
|
* idle waiting for tasks. This method may underestimate the |
875 |
|
* number of idle threads. |
876 |
< |
* @return the number of idle threads |
876 |
> |
* @return the number of idle threads. |
877 |
|
*/ |
878 |
|
final int getIdleThreadCount() { |
879 |
|
int c = runningCountOf(workerCounts) - activeCountOf(runControl); |
902 |
|
* tuning fork/join programs: In general, steal counts should be |
903 |
|
* high enough to keep threads busy, but low enough to avoid |
904 |
|
* overhead and contention across threads. |
905 |
< |
* @return the number of steals |
905 |
> |
* @return the number of steals. |
906 |
|
*/ |
907 |
|
public long getStealCount() { |
908 |
|
return stealCount.get(); |
925 |
|
* an approximation, obtained by iterating across all threads in |
926 |
|
* the pool. This method may be useful for tuning task |
927 |
|
* granularities. |
928 |
< |
* @return the number of queued tasks |
928 |
> |
* @return the number of queued tasks. |
929 |
|
*/ |
930 |
|
public long getQueuedTaskCount() { |
931 |
|
long count = 0; |
944 |
|
* Returns an estimate of the number tasks submitted to this pool |
945 |
|
* that have not yet begun executing. This method takes time |
946 |
|
* proportional to the number of submissions. |
947 |
< |
* @return the number of queued submissions |
947 |
> |
* @return the number of queued submissions. |
948 |
|
*/ |
949 |
|
public int getQueuedSubmissionCount() { |
950 |
|
return submissionQueue.size(); |
953 |
|
/** |
954 |
|
* Returns true if there are any tasks submitted to this pool |
955 |
|
* that have not yet begun executing. |
956 |
< |
* @return {@code true} if there are any queued submissions |
956 |
> |
* @return <code>true</code> if there are any queued submissions. |
957 |
|
*/ |
958 |
|
public boolean hasQueuedSubmissions() { |
959 |
|
return !submissionQueue.isEmpty(); |
973 |
|
* Removes all available unexecuted submitted and forked tasks |
974 |
|
* from scheduling queues and adds them to the given collection, |
975 |
|
* without altering their execution status. These may include |
976 |
< |
* artificially generated or wrapped tasks. This method is designed |
976 |
> |
* artifically generated or wrapped tasks. This method id designed |
977 |
|
* to be invoked only when the pool is known to be |
978 |
|
* quiescent. Invocations at other times may not remove all |
979 |
|
* tasks. A failure encountered while attempting to add elements |
980 |
< |
* to collection {@code c} may result in elements being in |
980 |
> |
* to collection <tt>c</tt> may result in elements being in |
981 |
|
* neither, either or both collections when the associated |
982 |
|
* exception is thrown. The behavior of this operation is |
983 |
|
* undefined if the specified collection is modified while the |
1045 |
|
* @throws SecurityException if a security manager exists and |
1046 |
|
* the caller is not permitted to modify threads |
1047 |
|
* because it does not hold {@link |
1048 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
1048 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
1049 |
|
*/ |
1050 |
|
public void shutdown() { |
1051 |
|
checkPermission(); |
1061 |
|
* method may or may not be rejected. Unlike some other executors, |
1062 |
|
* this method cancels rather than collects non-executed tasks |
1063 |
|
* upon termination, so always returns an empty list. However, you |
1064 |
< |
* can use method {@code drainTasksTo} before invoking this |
1064 |
> |
* can use method <code>drainTasksTo</code> before invoking this |
1065 |
|
* method to transfer unexecuted tasks to another collection. |
1066 |
|
* @return an empty list |
1067 |
|
* @throws SecurityException if a security manager exists and |
1068 |
|
* the caller is not permitted to modify threads |
1069 |
|
* because it does not hold {@link |
1070 |
< |
* java.lang.RuntimePermission}{@code ("modifyThread")}, |
1070 |
> |
* java.lang.RuntimePermission}<code>("modifyThread")</code>, |
1071 |
|
*/ |
1072 |
|
public List<Runnable> shutdownNow() { |
1073 |
|
checkPermission(); |
1076 |
|
} |
1077 |
|
|
1078 |
|
/** |
1079 |
< |
* Returns {@code true} if all tasks have completed following shut down. |
1079 |
> |
* Returns <code>true</code> if all tasks have completed following shut down. |
1080 |
|
* |
1081 |
< |
* @return {@code true} if all tasks have completed following shut down |
1081 |
> |
* @return <code>true</code> if all tasks have completed following shut down |
1082 |
|
*/ |
1083 |
|
public boolean isTerminated() { |
1084 |
|
return runStateOf(runControl) == TERMINATED; |
1085 |
|
} |
1086 |
|
|
1087 |
|
/** |
1088 |
< |
* Returns {@code true} if the process of termination has |
1088 |
> |
* Returns <code>true</code> if the process of termination has |
1089 |
|
* commenced but possibly not yet completed. |
1090 |
|
* |
1091 |
< |
* @return {@code true} if terminating |
1091 |
> |
* @return <code>true</code> if terminating |
1092 |
|
*/ |
1093 |
|
public boolean isTerminating() { |
1094 |
|
return runStateOf(runControl) >= TERMINATING; |
1095 |
|
} |
1096 |
|
|
1097 |
|
/** |
1098 |
< |
* Returns {@code true} if this pool has been shut down. |
1098 |
> |
* Returns <code>true</code> if this pool has been shut down. |
1099 |
|
* |
1100 |
< |
* @return {@code true} if this pool has been shut down |
1100 |
> |
* @return <code>true</code> if this pool has been shut down |
1101 |
|
*/ |
1102 |
|
public boolean isShutdown() { |
1103 |
|
return runStateOf(runControl) >= SHUTDOWN; |
1110 |
|
* |
1111 |
|
* @param timeout the maximum time to wait |
1112 |
|
* @param unit the time unit of the timeout argument |
1113 |
< |
* @return {@code true} if this executor terminated and |
1114 |
< |
* {@code false} if the timeout elapsed before termination |
1113 |
> |
* @return <code>true</code> if this executor terminated and |
1114 |
> |
* <code>false</code> if the timeout elapsed before termination |
1115 |
|
* @throws InterruptedException if interrupted while waiting |
1116 |
|
*/ |
1117 |
|
public boolean awaitTermination(long timeout, TimeUnit unit) |
1183 |
|
} |
1184 |
|
|
1185 |
|
/** |
1186 |
< |
* Possibly terminates when on shutdown state. |
1186 |
> |
* Possibly terminate when on shutdown state |
1187 |
|
*/ |
1188 |
|
private void terminateOnShutdown() { |
1189 |
|
if (!hasQueuedSubmissions() && canTerminateOnShutdown(runControl)) |
1191 |
|
} |
1192 |
|
|
1193 |
|
/** |
1194 |
< |
* Clears out and cancels submissions. |
1194 |
> |
* Clear out and cancel submissions |
1195 |
|
*/ |
1196 |
|
private void cancelQueuedSubmissions() { |
1197 |
|
ForkJoinTask<?> task; |
1200 |
|
} |
1201 |
|
|
1202 |
|
/** |
1203 |
< |
* Cleans out worker queues. |
1203 |
> |
* Clean out worker queues. |
1204 |
|
*/ |
1205 |
|
private void cancelQueuedWorkerTasks() { |
1206 |
|
final ReentrantLock lock = this.workerLock; |
1220 |
|
} |
1221 |
|
|
1222 |
|
/** |
1223 |
< |
* Sets each worker's status to terminating. Requires lock to avoid |
1224 |
< |
* conflicts with add/remove. |
1223 |
> |
* Set each worker's status to terminating. Requires lock to avoid |
1224 |
> |
* conflicts with add/remove |
1225 |
|
*/ |
1226 |
|
private void stopAllWorkers() { |
1227 |
|
final ReentrantLock lock = this.workerLock; |
1241 |
|
} |
1242 |
|
|
1243 |
|
/** |
1244 |
< |
* Interrupts all unterminated workers. This is not required for |
1244 |
> |
* Interrupt all unterminated workers. This is not required for |
1245 |
|
* sake of internal control, but may help unstick user code during |
1246 |
|
* shutdown. |
1247 |
|
*/ |
1311 |
|
} |
1312 |
|
|
1313 |
|
/** |
1314 |
< |
* Wakes up waiter, returning false if known to already |
1314 |
> |
* Wake up waiter, returning false if known to already |
1315 |
|
*/ |
1316 |
|
boolean signal() { |
1317 |
|
ForkJoinWorkerThread t = thread; |
1323 |
|
} |
1324 |
|
|
1325 |
|
/** |
1326 |
< |
* Awaits release on sync. |
1326 |
> |
* Await release on sync |
1327 |
|
*/ |
1328 |
|
void awaitSyncRelease(ForkJoinPool p) { |
1329 |
|
while (thread != null && !p.syncIsReleasable(this)) |
1331 |
|
} |
1332 |
|
|
1333 |
|
/** |
1334 |
< |
* Awaits resumption as spare. |
1334 |
> |
* Await resumption as spare |
1335 |
|
*/ |
1336 |
|
void awaitSpareRelease() { |
1337 |
|
while (thread != null) { |
1371 |
|
} |
1372 |
|
|
1373 |
|
/** |
1374 |
< |
* Signals threads waiting to poll a task. Because method sync |
1374 |
> |
* Signal threads waiting to poll a task. Because method sync |
1375 |
|
* rechecks availability, it is OK to only proceed if queue |
1376 |
|
* appears to be non-empty, and OK to skip under contention to |
1377 |
|
* increment count (since some other thread succeeded). |
1458 |
|
// Parallelism maintenance |
1459 |
|
|
1460 |
|
/** |
1461 |
< |
* Decrements running count; if too low, adds spare. |
1461 |
> |
* Decrement running count; if too low, add spare. |
1462 |
|
* |
1463 |
|
* Conceptually, all we need to do here is add or resume a |
1464 |
|
* spare thread when one is about to block (and remove or |
1478 |
|
* only be suspended or removed when they are idle, not |
1479 |
|
* immediately when they aren't needed. So adding threads will |
1480 |
|
* raise parallelism level for longer than necessary. Also, |
1481 |
< |
* FJ applications often encounter highly transient peaks when |
1481 |
> |
* FJ applications often enounter highly transient peaks when |
1482 |
|
* many threads are blocked joining, but for less time than it |
1483 |
|
* takes to create or resume spares. |
1484 |
|
* |
1507 |
|
/** |
1508 |
|
* Same idea as preJoin |
1509 |
|
*/ |
1510 |
< |
final boolean preBlock(ManagedBlocker blocker, boolean maintainParallelism){ |
1510 |
> |
final boolean preBlock(ManagedBlocker blocker, |
1511 |
> |
boolean maintainParallelism) { |
1512 |
|
maintainParallelism &= maintainsParallelism; |
1513 |
|
boolean dec = false; |
1514 |
|
while (spareStack == null || !tryResumeSpare(dec)) { |
1549 |
|
} |
1550 |
|
|
1551 |
|
/** |
1552 |
< |
* Adds a spare worker if lock available and no more than the |
1553 |
< |
* expected numbers of threads exist. |
1552 |
> |
* Add a spare worker if lock available and no more than the |
1553 |
> |
* expected numbers of threads exist |
1554 |
|
* @return true if successful |
1555 |
|
*/ |
1556 |
|
private boolean tryAddSpare(int expectedCounts) { |
1583 |
|
} |
1584 |
|
|
1585 |
|
/** |
1586 |
< |
* Adds the kth spare worker. On entry, pool counts are already |
1586 |
> |
* Add the kth spare worker. On entry, pool coounts are already |
1587 |
|
* adjusted to reflect addition. |
1588 |
|
*/ |
1589 |
|
private void createAndStartSpare(int k) { |
1605 |
|
} |
1606 |
|
|
1607 |
|
/** |
1608 |
< |
* Suspends calling thread w if there are excess threads. Called |
1609 |
< |
* only from sync. Spares are enqueued in a Treiber stack using |
1610 |
< |
* the same WaitQueueNodes as barriers. They are resumed mainly |
1611 |
< |
* in preJoin, but are also woken on pool events that require all |
1612 |
< |
* threads to check run state. |
1608 |
> |
* Suspend calling thread w if there are excess threads. Called |
1609 |
> |
* only from sync. Spares are enqueued in a Treiber stack |
1610 |
> |
* using the same WaitQueueNodes as barriers. They are resumed |
1611 |
> |
* mainly in preJoin, but are also woken on pool events that |
1612 |
> |
* require all threads to check run state. |
1613 |
|
* @param w the caller |
1614 |
|
*/ |
1615 |
|
private boolean suspendIfSpare(ForkJoinWorkerThread w) { |
1630 |
|
} |
1631 |
|
|
1632 |
|
/** |
1633 |
< |
* Tries to pop and resume a spare thread. |
1633 |
> |
* Try to pop and resume a spare thread. |
1634 |
|
* @param updateCount if true, increment running count on success |
1635 |
|
* @return true if successful |
1636 |
|
*/ |
1648 |
|
} |
1649 |
|
|
1650 |
|
/** |
1651 |
< |
* Pops and resumes all spare threads. Same idea as ensureSync. |
1651 |
> |
* Pop and resume all spare threads. Same idea as ensureSync. |
1652 |
|
* @return true if any spares released |
1653 |
|
*/ |
1654 |
|
private boolean resumeAllSpares() { |
1666 |
|
} |
1667 |
|
|
1668 |
|
/** |
1669 |
< |
* Pops and shuts down excessive spare threads. Call only while |
1669 |
> |
* Pop and shutdown excessive spare threads. Call only while |
1670 |
|
* holding lock. This is not guaranteed to eliminate all excess |
1671 |
|
* threads, only those suspended as spares, which are the ones |
1672 |
|
* unlikely to be needed in the future. |
1691 |
|
/** |
1692 |
|
* Interface for extending managed parallelism for tasks running |
1693 |
|
* in ForkJoinPools. A ManagedBlocker provides two methods. |
1694 |
< |
* Method {@code isReleasable} must return true if blocking is not |
1695 |
< |
* necessary. Method {@code block} blocks the current thread |
1694 |
> |
* Method <code>isReleasable</code> must return true if blocking is not |
1695 |
> |
* necessary. Method <code>block</code> blocks the current thread |
1696 |
|
* if necessary (perhaps internally invoking isReleasable before |
1697 |
|
* actually blocking.). |
1698 |
|
* <p>For example, here is a ManagedBlocker based on a |
1718 |
|
* Possibly blocks the current thread, for example waiting for |
1719 |
|
* a lock or condition. |
1720 |
|
* @return true if no additional blocking is necessary (i.e., |
1721 |
< |
* if isReleasable would return true) |
1721 |
> |
* if isReleasable would return true). |
1722 |
|
* @throws InterruptedException if interrupted while waiting |
1723 |
< |
* (the method is not required to do so, but is allowed to). |
1723 |
> |
* (the method is not required to do so, but is allowe to). |
1724 |
|
*/ |
1725 |
|
boolean block() throws InterruptedException; |
1726 |
|
|
1735 |
|
* is a ForkJoinWorkerThread, this method possibly arranges for a |
1736 |
|
* spare thread to be activated if necessary to ensure parallelism |
1737 |
|
* while the current thread is blocked. If |
1738 |
< |
* {@code maintainParallelism} is true and the pool supports |
1738 |
> |
* <code>maintainParallelism</code> is true and the pool supports |
1739 |
|
* it ({@link #getMaintainsParallelism}), this method attempts to |
1740 |
|
* maintain the pool's nominal parallelism. Otherwise if activates |
1741 |
|
* a thread only if necessary to avoid complete starvation. This |
1757 |
|
* attempt to maintain the pool's nominal parallelism; otherwise |
1758 |
|
* activate a thread only if necessary to avoid complete |
1759 |
|
* starvation. |
1760 |
< |
* @throws InterruptedException if blocker.block did so |
1760 |
> |
* @throws InterruptedException if blocker.block did so. |
1761 |
|
*/ |
1762 |
|
public static void managedBlock(ManagedBlocker blocker, |
1763 |
|
boolean maintainParallelism) |