ForkJoinWorkerThread

public class ForkJoinWorkerThread
extends Thread

java.lang.Object
   ↳ java.lang.Thread
     ↳ java.util.concurrent.ForkJoinWorkerThread


A thread managed by a ForkJoinPool, which executes ForkJoinTasks. 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 to use it in a ForkJoinPool.

Summary

Inherited constants

int MAX_PRIORITY

The maximum priority that a thread can have.

int MIN_PRIORITY

The minimum priority that a thread can have.

int NORM_PRIORITY

The default priority that is assigned to a thread.

Protected constructors

ForkJoinWorkerThread(ForkJoinPool pool)

Creates a ForkJoinWorkerThread operating in the given pool.

Public methods

ForkJoinPool getPool()

Returns the pool hosting this thread.

int getPoolIndex()

Returns the unique index number of this thread in its pool.

void run()

This method is required to be public, but should never be called explicitly.

Protected methods

void onStart()

Initializes internal state after construction but before processing any tasks.

void onTermination(Throwable exception)

Performs cleanup associated with termination of this worker thread.

Inherited methods

static int activeCount()

Returns an estimate of the number of active threads in the current thread's thread group and its subgroups.

final void checkAccess()

Determines if the currently running thread has permission to modify this thread.

Object clone()

Throws CloneNotSupportedException as a Thread can not be meaningfully cloned.

int countStackFrames()

This method was deprecated in API level 15. The definition of this call depends on suspend(), which is deprecated. Further, the results of this call were never well-defined. This method is subject to removal in a future version of Java SE.

static Thread currentThread()

Returns a reference to the currently executing thread object.

void destroy()

This method was deprecated in API level 15. This method was originally designed to destroy this thread without any cleanup. Any monitors it held would have remained locked. However, the method was never implemented. If if were to be implemented, it would be deadlock-prone in much the manner of suspend(). If the target thread held a lock protecting a critical system resource when it was destroyed, no thread could ever access this resource again. If another thread ever attempted to lock this resource, deadlock would result. Such deadlocks typically manifest themselves as "frozen" processes. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

static void dumpStack()

Prints a stack trace of the current thread to the standard error stream.

static int enumerate(Thread[] tarray)

Copies into the specified array every active thread in the current thread's thread group and its subgroups.

static Map<ThreadStackTraceElement[]> getAllStackTraces()

Returns a map of stack traces for all live threads.

ClassLoader getContextClassLoader()

Returns the context ClassLoader for this thread.

static Thread.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()

Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception.

long getId()

Returns the identifier of this Thread.

final String getName()

Returns this thread's name.

final int getPriority()

Returns this thread's priority.

StackTraceElement[] getStackTrace()

Returns an array of stack trace elements representing the stack dump of this thread.

Thread.State getState()

Returns the state of this thread.

final ThreadGroup getThreadGroup()

Returns the thread group to which this thread belongs.

Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()

Returns the handler invoked when this thread abruptly terminates due to an uncaught exception.

static boolean holdsLock(Object obj)

Returns true if and only if the current thread holds the monitor lock on the specified object.

void interrupt()

Interrupts this thread.

static boolean interrupted()

Tests whether the current thread has been interrupted.

final boolean isAlive()

Tests if this thread is alive.

final boolean isDaemon()

Tests if this thread is a daemon thread.

boolean isInterrupted()

Tests whether this thread has been interrupted.

final void join()

Waits for this thread to die.

final void join(long millis)

Waits at most millis milliseconds for this thread to die.

final void join(long millis, int nanos)

Waits at most millis milliseconds plus nanos nanoseconds for this thread to die.

static void onSpinWait()

Indicates that the caller is momentarily unable to progress, until the occurrence of one or more actions on the part of other activities.

final void resume()

This method was deprecated in API level 15. This method exists solely for use with suspend(), which has been deprecated because it is deadlock-prone. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

void run()

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

void setContextClassLoader(ClassLoader cl)

Sets the context ClassLoader for this Thread.

final void setDaemon(boolean on)

Marks this thread as either a daemon thread or a user thread.

static void setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)

Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.

final void setName(String name)

Changes the name of this thread to be equal to the argument name.

final void setPriority(int newPriority)

Changes the priority of this thread.

void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)

Set the handler invoked when this thread abruptly terminates due to an uncaught exception.

static void sleep(long millis, int nanos)

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers.

static void sleep(long millis)

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers.

void start()

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

final void stop()

This method was deprecated in API level 15. This method was originally designed to force a thread to stop and throw a ThreadDeath as an exception. It was inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the unchecked ThreadDeath exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, potentially resulting in arbitrary behavior. Many uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable, for example), the interrupt method should be used to interrupt the wait. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

final void stop(Throwable obj)

This method was deprecated in API level 15. This method was originally designed to force a thread to stop and throw a given Throwable as an exception. It was inherently unsafe (see stop() for details), and furthermore could be used to generate exceptions that the target thread was not prepared to handle. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

final void suspend()

This method was deprecated in API level 15. This method has been deprecated, as it is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, deadlock results. Such deadlocks typically manifest themselves as "frozen" processes. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

String toString()

Returns a string representation of this thread, including the thread's name, priority, and thread group.

static void yield()

A hint to the scheduler that the current thread is willing to yield its current use of a processor.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

abstract void run()

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Protected constructors

ForkJoinWorkerThread

Added in API level 21
protected ForkJoinWorkerThread (ForkJoinPool pool)

Creates a ForkJoinWorkerThread operating in the given pool.

Parameters
pool ForkJoinPool: the pool this thread works in

Throws
NullPointerException if pool is null

Public methods

getPool

Added in API level 21
public ForkJoinPool getPool ()

Returns the pool hosting this thread.

Returns
ForkJoinPool the pool

getPoolIndex

Added in API level 21
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
int the index number

run

Added in API level 21
public void run ()

This method is required to be public, but should never be called explicitly. It performs the main run loop to execute ForkJoinTasks.

Protected methods

onStart

Added in API level 21
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

Added in API level 21
protected void onTermination (Throwable 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 Throwable: the exception causing this thread to abort due to an unrecoverable error, or null if completed normally

In the Motion Editor, you can quickly build animation by dragging animation elements into a visual design editor instead of writing the MotionLayout XML by hand.

Updated Apr 12, 2023

Discover the latest app development tools, platform updates, training, and documentation for developers across every Android device.

Updated Oct 2, 2024

The Draw 9-patch tool is a WYSIWYG editor included in Android Studio that lets you create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen.

Updated Apr 12, 2023