311 |
|
} |
312 |
|
|
313 |
|
/** |
314 |
< |
* Returns true if argument represents zero active count and |
315 |
< |
* nonzero runstate, which is the triggering condition for |
314 |
> |
* Returns {@code true} if argument represents zero active count |
315 |
> |
* and nonzero runstate, which is the triggering condition for |
316 |
|
* terminating on shutdown. |
317 |
|
*/ |
318 |
|
private static boolean canTerminateOnShutdown(int c) { |
720 |
|
* Returns the handler for internal worker threads that terminate |
721 |
|
* due to unrecoverable errors encountered while executing tasks. |
722 |
|
* |
723 |
< |
* @return the handler, or null if none |
723 |
> |
* @return the handler, or {@code null} if none |
724 |
|
*/ |
725 |
|
public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() { |
726 |
|
Thread.UncaughtExceptionHandler h; |
741 |
|
* as handler. |
742 |
|
* |
743 |
|
* @param h the new handler |
744 |
< |
* @return the old handler, or null if none |
744 |
> |
* @return the old handler, or {@code null} if none |
745 |
|
* @throws SecurityException if a security manager exists and |
746 |
|
* the caller is not permitted to modify threads |
747 |
|
* because it does not hold {@link |
851 |
|
|
852 |
|
|
853 |
|
/** |
854 |
< |
* Returns true if this pool dynamically maintains its target |
855 |
< |
* parallelism level. If false, new threads are added only to |
856 |
< |
* avoid possible starvation. |
857 |
< |
* This setting is by default true. |
854 |
> |
* Returns {@code true} if this pool dynamically maintains its |
855 |
> |
* target parallelism level. If false, new threads are added only |
856 |
> |
* to avoid possible starvation. This setting is by default true. |
857 |
|
* |
858 |
< |
* @return true if maintains parallelism |
858 |
> |
* @return {@code true} if maintains parallelism |
859 |
|
*/ |
860 |
|
public boolean getMaintainsParallelism() { |
861 |
|
return maintainsParallelism; |
866 |
|
* parallelism level. If false, new threads are added only to |
867 |
|
* avoid possible starvation. |
868 |
|
* |
869 |
< |
* @param enable true to maintains parallelism |
869 |
> |
* @param enable {@code true} to maintain parallelism |
870 |
|
*/ |
871 |
|
public void setMaintainsParallelism(boolean enable) { |
872 |
|
maintainsParallelism = enable; |
899 |
|
} |
900 |
|
|
901 |
|
/** |
902 |
< |
* Returns true if this pool uses local first-in-first-out |
902 |
> |
* Returns {@code true} if this pool uses local first-in-first-out |
903 |
|
* scheduling mode for forked tasks that are never joined. |
904 |
|
* |
905 |
< |
* @return true if this pool uses async mode |
905 |
> |
* @return {@code true} if this pool uses async mode |
906 |
|
*/ |
907 |
|
public boolean getAsyncMode() { |
908 |
|
return locallyFifo; |
943 |
|
} |
944 |
|
|
945 |
|
/** |
946 |
< |
* Returns true if all worker threads are currently idle. An idle |
947 |
< |
* worker is one that cannot obtain a task to execute because none |
948 |
< |
* are available to steal from other threads, and there are no |
949 |
< |
* pending submissions to the pool. This method is conservative; |
950 |
< |
* it might not return true immediately upon idleness of all |
951 |
< |
* threads, but will eventually become true if threads remain |
952 |
< |
* inactive. |
946 |
> |
* Returns {@code true} if all worker threads are currently idle. |
947 |
> |
* An idle worker is one that cannot obtain a task to execute |
948 |
> |
* because none are available to steal from other threads, and |
949 |
> |
* there are no pending submissions to the pool. This method is |
950 |
> |
* conservative; it might not return {@code true} immediately upon |
951 |
> |
* idleness of all threads, but will eventually become true if |
952 |
> |
* threads remain inactive. |
953 |
|
* |
954 |
< |
* @return true if all threads are currently idle |
954 |
> |
* @return {@code true} if all threads are currently idle |
955 |
|
*/ |
956 |
|
public boolean isQuiescent() { |
957 |
|
return activeCountOf(runControl) == 0; |
1017 |
|
} |
1018 |
|
|
1019 |
|
/** |
1020 |
< |
* Returns true if there are any tasks submitted to this pool |
1021 |
< |
* that have not yet begun executing. |
1020 |
> |
* Returns {@code true} if there are any tasks submitted to this |
1021 |
> |
* pool that have not yet begun executing. |
1022 |
|
* |
1023 |
|
* @return {@code true} if there are any queued submissions |
1024 |
|
*/ |
1031 |
|
* available. This method may be useful in extensions to this |
1032 |
|
* class that re-assign work in systems with multiple pools. |
1033 |
|
* |
1034 |
< |
* @return the next submission, or null if none |
1034 |
> |
* @return the next submission, or {@code null} if none |
1035 |
|
*/ |
1036 |
|
protected ForkJoinTask<?> pollSubmission() { |
1037 |
|
return submissionQueue.poll(); |
1491 |
|
} |
1492 |
|
|
1493 |
|
/** |
1494 |
< |
* Returns true if worker waiting on sync can proceed: |
1494 |
> |
* Returns {@code true} if worker waiting on sync can proceed: |
1495 |
|
* - on signal (thread == null) |
1496 |
|
* - on event count advance (winning race to notify vs signaller) |
1497 |
|
* - on interrupt |
1499 |
|
* If node was not signalled and event count not advanced on exit, |
1500 |
|
* then we also help advance event count. |
1501 |
|
* |
1502 |
< |
* @return true if node can be released |
1502 |
> |
* @return {@code true} if node can be released |
1503 |
|
*/ |
1504 |
|
final boolean syncIsReleasable(WaitQueueNode node) { |
1505 |
|
long prev = node.count; |
1518 |
|
} |
1519 |
|
|
1520 |
|
/** |
1521 |
< |
* Returns true if a new sync event occurred since last call to |
1522 |
< |
* sync or this method, if so, updating caller's count. |
1521 |
> |
* Returns {@code true} if a new sync event occurred since last |
1522 |
> |
* call to sync or this method, if so, updating caller's count. |
1523 |
|
*/ |
1524 |
|
final boolean hasNewSyncEvent(ForkJoinWorkerThread w) { |
1525 |
|
long lc = w.lastEventCount; |
1603 |
|
} |
1604 |
|
|
1605 |
|
/** |
1606 |
< |
* Returns true if a spare thread appears to be needed. If |
1607 |
< |
* maintaining parallelism, returns true when the deficit in |
1606 |
> |
* Returns {@code true} if a spare thread appears to be needed. |
1607 |
> |
* If maintaining parallelism, returns true when the deficit in |
1608 |
|
* running threads is more than the surplus of total threads, and |
1609 |
|
* there is apparently some work to do. This self-limiting rule |
1610 |
|
* means that the more threads that have already been added, the |
1773 |
|
/** |
1774 |
|
* Interface for extending managed parallelism for tasks running |
1775 |
|
* in ForkJoinPools. A ManagedBlocker provides two methods. |
1776 |
< |
* Method {@code isReleasable} must return true if blocking is not |
1777 |
< |
* necessary. Method {@code block} blocks the current thread if |
1778 |
< |
* necessary (perhaps internally invoking {@code isReleasable} |
1779 |
< |
* before actually blocking.). |
1776 |
> |
* Method {@code isReleasable} must return {@code true} if |
1777 |
> |
* blocking is not necessary. Method {@code block} blocks the |
1778 |
> |
* current thread if necessary (perhaps internally invoking |
1779 |
> |
* {@code isReleasable} before actually blocking.). |
1780 |
|
* |
1781 |
|
* <p>For example, here is a ManagedBlocker based on a |
1782 |
|
* ReentrantLock: |
1800 |
|
* Possibly blocks the current thread, for example waiting for |
1801 |
|
* a lock or condition. |
1802 |
|
* |
1803 |
< |
* @return true if no additional blocking is necessary (i.e., |
1804 |
< |
* if isReleasable would return true) |
1803 |
> |
* @return {@code true} if no additional blocking is necessary |
1804 |
> |
* (i.e., if isReleasable would return true) |
1805 |
|
* @throws InterruptedException if interrupted while waiting |
1806 |
|
* (the method is not required to do so, but is allowed to) |
1807 |
|
*/ |
1808 |
|
boolean block() throws InterruptedException; |
1809 |
|
|
1810 |
|
/** |
1811 |
< |
* Returns true if blocking is unnecessary. |
1811 |
> |
* Returns {@code true} if blocking is unnecessary. |
1812 |
|
*/ |
1813 |
|
boolean isReleasable(); |
1814 |
|
} |
1818 |
|
* is a ForkJoinWorkerThread, this method possibly arranges for a |
1819 |
|
* spare thread to be activated if necessary to ensure parallelism |
1820 |
|
* while the current thread is blocked. If |
1821 |
< |
* {@code maintainParallelism} is true and the pool supports |
1821 |
> |
* {@code maintainParallelism} is {@code true} and the pool supports |
1822 |
|
* it ({@link #getMaintainsParallelism}), this method attempts to |
1823 |
|
* maintain the pool's nominal parallelism. Otherwise it activates |
1824 |
|
* a thread only if necessary to avoid complete starvation. This |
1836 |
|
* be expanded to ensure parallelism, and later adjusted. |
1837 |
|
* |
1838 |
|
* @param blocker the blocker |
1839 |
< |
* @param maintainParallelism if true and supported by this pool, |
1840 |
< |
* attempt to maintain the pool's nominal parallelism; otherwise |
1841 |
< |
* activate a thread only if necessary to avoid complete |
1842 |
< |
* starvation. |
1839 |
> |
* @param maintainParallelism if {@code true} and supported by |
1840 |
> |
* this pool, attempt to maintain the pool's nominal parallelism; |
1841 |
> |
* otherwise activate a thread only if necessary to avoid |
1842 |
> |
* complete starvation. |
1843 |
|
* @throws InterruptedException if blocker.block did so |
1844 |
|
*/ |
1845 |
|
public static void managedBlock(ManagedBlocker blocker, |