Thread (Java SE 26 & JDK 26)
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
ForkJoinWorkerThread
-
Nested Class Summary
Nested Classes
static interfacestatic enumstatic interfaceInterface for handlers invoked when a
Threadabruptly terminates due to an uncaught exception. -
Field Summary
Fields
static final intThe maximum priority that a thread can have.
static final intThe minimum priority that a thread can have.
static final intThe default priority that is assigned to a thread.
-
Constructor Summary
Constructors
Thread()Initializes a new platform
Thread.Initializes a new platform
Thread.Initializes a new platform
Thread.Initializes a new platform
Thread.Initializes a new platform
Thread.Initializes a new platform
Threadso that it hastaskas its run object, has the specifiednameas its name, and belongs to the thread group referred to bygroup.Initializes a new platform
Threadso that it hastaskas its run object, has the specifiednameas its name, and belongs to the thread group referred to bygroup, and has the specified stack size.Thread(ThreadGroup group, Runnable task, String name, long stackSize, boolean inheritInheritableThreadLocals) Initializes a new platform
Threadso that it hastaskas its run object, has the specifiednameas its name, belongs to the thread group referred to bygroup, has the specifiedstackSize, and inherits initial values for inheritable thread-local variables ifinheritThreadLocalsistrue.Initializes a new platform
Thread. -
Method Summary
static intReturns an estimate of the number of live platform threads in the current thread's thread group and its subgroups.
final voidDeprecated, for removal: This API element is subject to removal in a future version.
clone()Throws CloneNotSupportedException as a Thread can not be meaningfully cloned.
Returns the Thread object for the current thread.
static voidPrints a stack trace of the current thread to the standard error stream.
static intCopies into the specified array every live platform thread in the current thread's thread group and its subgroups.
Returns a map of stack traces for all live platform threads.
Returns the context
ClassLoaderfor this thread.Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception.
longgetId()getName()Returns this thread's name.
final intReturns this thread's priority.
Returns an array of stack trace elements representing the stack dump of this thread.
getState()Returns the state of this thread.
Returns the thread's thread group or
nullif the thread has terminated.Returns the handler invoked when this thread abruptly terminates due to an uncaught exception.
static booleanReturns
trueif and only if the current thread holds the monitor lock on the specified object.voidstatic booleanTests whether the current thread has been interrupted.
final booleanisAlive()Tests if this thread is alive.
final booleanisDaemon()Tests if this thread is a daemon thread.
booleanTests whether this thread has been interrupted.
final booleanReturns
trueif this thread is a virtual thread.final voidjoin()Waits for this thread to terminate.
final voidjoin(long millis) Waits at most
millismilliseconds for this thread to terminate.final voidjoin(long millis, int nanos) Waits at most
millismilliseconds plusnanosnanoseconds for this thread to terminate.final booleanWaits for this thread to terminate for up to the given waiting duration.
Returns a builder for creating a platform
ThreadorThreadFactorythat creates platform threads.Returns a builder for creating a virtual
ThreadorThreadFactorythat creates virtual threads.static voidIndicates that the caller is momentarily unable to progress, until the occurrence of one or more actions on the part of other activities.
voidrun()This method is run by the thread when it executes.
voidSets the context
ClassLoaderfor this thread.final voidsetDaemon(boolean on) Marks this thread as either a daemon or non-daemon thread.
static voidSet 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 voidChanges the name of this thread to be equal to the argument
name.final voidsetPriority(int newPriority) Changes the priority of this thread.
voidSet the handler invoked when this thread abruptly terminates due to an uncaught exception.
static voidsleep(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.
static voidsleep(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 voidCauses the currently executing thread to sleep (temporarily cease execution) for the specified duration, subject to the precision and accuracy of system timers and schedulers.
voidstart()Schedules this thread to begin execution.
Creates a virtual thread to execute a task and schedules it to execute.
final longthreadId()Returns the identifier of this Thread.
toString()Returns a string representation of this thread.
static voidyield()A hint to the scheduler that the current thread is willing to yield its current use of a processor.
Methods declared in class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbooleanIndicates whether some other object is "equal to" this one.
protected voidDeprecated, for removal: This API element is subject to removal in a future version.
Returns the runtime class of this
Object.intReturns a hash code value for this object.
final voidWakes up a single thread that is waiting on this object's monitor.
final voidWakes up all threads that are waiting on this object's monitor.
final voidCauses the current thread to wait until it is awakened, typically by being notified or interrupted.
final voidwait(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 voidwait(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.
-
Field Details
-
MIN_PRIORITY
-
NORM_PRIORITY
-
MAX_PRIORITY
-
-
Constructor Details
-
Thread
-
Thread
-
Thread
-
Thread
-
Thread
-
Thread
-
Thread
-
Thread
-
Thread
-
-
Method Details
-
currentThread
-
yield
-
sleep
-
sleep
-
sleep
-
onSpinWait
-
ofPlatform
-
ofVirtual
-
clone
-
startVirtualThread
-
isVirtual
-
start
-
run
-
interrupt
-
interrupted
-
isInterrupted
-
isAlive
-
setPriority
-
getPriority
-
setName
-
getName
-
getThreadGroup
-
activeCount
-
enumerate
-
join
-
join
-
join
-
join
-
dumpStack
-
setDaemon
-
isDaemon
-
checkAccess
-
toString
-
getContextClassLoader
-
setContextClassLoader
-
holdsLock
-
getStackTrace
-
getAllStackTraces
-
getId
-
threadId
-
getState
-
setDefaultUncaughtExceptionHandler
-
getDefaultUncaughtExceptionHandler
-
getUncaughtExceptionHandler
-
setUncaughtExceptionHandler
-