ForkJoinWorkerThread (Java Platform SE 8 ) (original) (raw)
- java.lang.Thread
- java.util.concurrent.ForkJoinWorkerThread
All Implemented Interfaces:
Runnable
public class ForkJoinWorkerThread
extends Thread
A thread managed by a ForkJoinPool, which executesForkJoinTasks. This class is subclassable solely for the sake of adding functionality -- there are no overridable methods dealing with scheduling or execution. However, you can override initialization and termination methods surrounding the main task processing loop. If you do create such a subclass, you will also need to supply a custom ForkJoinPool.ForkJoinWorkerThreadFactory touse it in a ForkJoinPool
.
Since:
1.7
Nested Class Summary
* ### Nested classes/interfaces inherited from class java.lang.[Thread](../../../java/lang/Thread.html "class in java.lang") `[Thread.State](../../../java/lang/Thread.State.html "enum in java.lang"), [Thread.UncaughtExceptionHandler](../../../java/lang/Thread.UncaughtExceptionHandler.html "interface in java.lang")`
Field Summary
* ### Fields inherited from class java.lang.[Thread](../../../java/lang/Thread.html "class in java.lang") `[MAX_PRIORITY](../../../java/lang/Thread.html#MAX%5FPRIORITY), [MIN_PRIORITY](../../../java/lang/Thread.html#MIN%5FPRIORITY), [NORM_PRIORITY](../../../java/lang/Thread.html#NORM%5FPRIORITY)`
Constructor Summary
Constructors
Modifier Constructor Description protected ForkJoinWorkerThread(ForkJoinPool pool) Creates a ForkJoinWorkerThread operating in the given pool. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description ForkJoinPool getPool() Returns the pool hosting this thread. int getPoolIndex() Returns the unique index number of this thread in its pool. protected void onStart() Initializes internal state after construction but before processing any tasks. protected void onTermination(Throwable exception) Performs cleanup associated with termination of this worker thread. void run() This method is required to be public, but should never be called explicitly. * ### Methods inherited from class java.lang.[Thread](../../../java/lang/Thread.html "class in java.lang") `[activeCount](../../../java/lang/Thread.html#activeCount--), [checkAccess](../../../java/lang/Thread.html#checkAccess--), [clone](../../../java/lang/Thread.html#clone--), [countStackFrames](../../../java/lang/Thread.html#countStackFrames--), [currentThread](../../../java/lang/Thread.html#currentThread--), [destroy](../../../java/lang/Thread.html#destroy--), [dumpStack](../../../java/lang/Thread.html#dumpStack--), [enumerate](../../../java/lang/Thread.html#enumerate-java.lang.Thread:A-), [getAllStackTraces](../../../java/lang/Thread.html#getAllStackTraces--), [getContextClassLoader](../../../java/lang/Thread.html#getContextClassLoader--), [getDefaultUncaughtExceptionHandler](../../../java/lang/Thread.html#getDefaultUncaughtExceptionHandler--), [getId](../../../java/lang/Thread.html#getId--), [getName](../../../java/lang/Thread.html#getName--), [getPriority](../../../java/lang/Thread.html#getPriority--), [getStackTrace](../../../java/lang/Thread.html#getStackTrace--), [getState](../../../java/lang/Thread.html#getState--), [getThreadGroup](../../../java/lang/Thread.html#getThreadGroup--), [getUncaughtExceptionHandler](../../../java/lang/Thread.html#getUncaughtExceptionHandler--), [holdsLock](../../../java/lang/Thread.html#holdsLock-java.lang.Object-), [interrupt](../../../java/lang/Thread.html#interrupt--), [interrupted](../../../java/lang/Thread.html#interrupted--), [isAlive](../../../java/lang/Thread.html#isAlive--), [isDaemon](../../../java/lang/Thread.html#isDaemon--), [isInterrupted](../../../java/lang/Thread.html#isInterrupted--), [join](../../../java/lang/Thread.html#join--), [join](../../../java/lang/Thread.html#join-long-), [join](../../../java/lang/Thread.html#join-long-int-), [resume](../../../java/lang/Thread.html#resume--), [setContextClassLoader](../../../java/lang/Thread.html#setContextClassLoader-java.lang.ClassLoader-), [setDaemon](../../../java/lang/Thread.html#setDaemon-boolean-), [setDefaultUncaughtExceptionHandler](../../../java/lang/Thread.html#setDefaultUncaughtExceptionHandler-java.lang.Thread.UncaughtExceptionHandler-), [setName](../../../java/lang/Thread.html#setName-java.lang.String-), [setPriority](../../../java/lang/Thread.html#setPriority-int-), [setUncaughtExceptionHandler](../../../java/lang/Thread.html#setUncaughtExceptionHandler-java.lang.Thread.UncaughtExceptionHandler-), [sleep](../../../java/lang/Thread.html#sleep-long-), [sleep](../../../java/lang/Thread.html#sleep-long-int-), [start](../../../java/lang/Thread.html#start--), [stop](../../../java/lang/Thread.html#stop--), [stop](../../../java/lang/Thread.html#stop-java.lang.Throwable-), [suspend](../../../java/lang/Thread.html#suspend--), [toString](../../../java/lang/Thread.html#toString--), [yield](../../../java/lang/Thread.html#yield--)` * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### ForkJoinWorkerThread protected ForkJoinWorkerThread([ForkJoinPool](../../../java/util/concurrent/ForkJoinPool.html "class in java.util.concurrent") pool) Creates a ForkJoinWorkerThread operating in the given pool. Parameters: `pool` \- the pool this thread works in Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if pool is null
Method Detail
* #### getPool public [ForkJoinPool](../../../java/util/concurrent/ForkJoinPool.html "class in java.util.concurrent") getPool() Returns the pool hosting this thread. Returns: the pool * #### getPoolIndex public int getPoolIndex() Returns the unique index number of this thread in its pool. The returned value ranges from zero to the maximum number of threads (minus one) that may exist in the pool, and does not change during the lifetime of the thread. This method may be useful for applications that track status or collect results per-worker-thread rather than per-task. Returns: the index number * #### onStart protected void onStart() Initializes internal state after construction but before processing any tasks. If you override this method, you must invoke `super.onStart()` at the beginning of the method. Initialization requires care: Most fields must have legal default values, to ensure that attempted accesses from other threads work correctly even before this thread starts processing tasks. * #### onTermination protected void onTermination([Throwable](../../../java/lang/Throwable.html "class in java.lang") exception) Performs cleanup associated with termination of this worker thread. If you override this method, you must invoke`super.onTermination` at the end of the overridden method. Parameters: `exception` \- the exception causing this thread to abort due to an unrecoverable error, or `null` if completed normally * #### run public void run() This method is required to be public, but should never be called explicitly. It performs the main run loop to execute[ForkJoinTask](../../../java/util/concurrent/ForkJoinTask.html "class in java.util.concurrent")s. Specified by: `[run](../../../java/lang/Runnable.html#run--)` in interface `[Runnable](../../../java/lang/Runnable.html "interface in java.lang")` Overrides: `[run](../../../java/lang/Thread.html#run--)` in class `[Thread](../../../java/lang/Thread.html "class in java.lang")` See Also: [Thread.start()](../../../java/lang/Thread.html#start--), [Thread.stop()](../../../java/lang/Thread.html#stop--), [Thread.Thread(ThreadGroup, Runnable, String)](../../../java/lang/Thread.html#Thread-java.lang.ThreadGroup-java.lang.Runnable-java.lang.String-)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.