| java.lang.Object | |
| ↳ | java.lang.Thread |
Known Direct Subclasses
|
A Thread is a unit of concurrent execution. It has its own call stack for methods being called and their parameters. Threads in the same VM interact and synchronize by the use of shared Objects and monitors associated with these objects. Synchronized methods and part of the API in Object also allow Threads to cooperate.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Thread.State | A representation of a thread's state. | ||||||||||
| Thread.UncaughtExceptionHandler | Implemented by objects that want to handle cases where a thread is being terminated by an uncaught exception. | ||||||||||
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | MAX_PRIORITY | The maximum priority value allowed for a thread. |
|||||||||
| int | MIN_PRIORITY | The minimum priority value allowed for a thread. |
|||||||||
| int | NORM_PRIORITY | The normal (default) priority value assigned to threads. |
|||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new Thread with no runnable object and a newly generated
name.
| |||||||||||
Constructs a new Thread with a runnable object and a newly generated
name.
| |||||||||||
Constructs a new Thread with a runnable object and name provided.
| |||||||||||
Constructs a new Thread with no runnable object and the name provided.
| |||||||||||
Constructs a new Thread with a runnable object and a newly generated
name.
| |||||||||||
Constructs a new Thread with a runnable object, the given name and
belonging to the ThreadGroup passed as parameter.
| |||||||||||
Constructs a new Thread with no runnable object, the given name and
belonging to the ThreadGroup passed as parameter.
| |||||||||||
Constructs a new Thread with a runnable object, the given name and
belonging to the ThreadGroup passed as parameter.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Returns the number of active threads in the running thread's ThreadGroup
and its subgroups.
| |||||||||||
This method is used for operations that require approval from a
SecurityManager.
| |||||||||||
This method is deprecated.
The results of this call were never well defined. To make
things worse, it would depend if the Thread was suspended or
not, and suspend was deprecated too.
| |||||||||||
Returns the instance of Thread that corresponds to the running Thread
which calls this method.
| |||||||||||
This method is deprecated.
Not implemented.
| |||||||||||
Prints a text representation of the stack for this Thread.
| |||||||||||
Copies an array with all Threads which are in the same ThreadGroup as the
receiver - and subgroups - into the array
threads passed
as parameter. | |||||||||||
Returns the stack traces of all the currently live threads and puts them into the given map. | |||||||||||
Returns the context ClassLoader for the receiver.
| |||||||||||
Returns the default exception handler that's executed when uncaught exception terminates a thread. | |||||||||||
Returns the thread's identifier. | |||||||||||
Returns the name of the receiver.
| |||||||||||
Returns the priority of the receiver.
| |||||||||||
Returns the current stack trace of the thread. | |||||||||||
Returns the current state of the thread for monitoring purposes. | |||||||||||
Returns the ThreadGroup to which the receiver belongs
| |||||||||||
Returns the thread's uncaught exception handler. | |||||||||||
Returns whether the current thread has a monitor lock on the specified
object.
| |||||||||||
Posts an interrupt request to the receiver.
| |||||||||||
Returns a
boolean indicating whether the current Thread (
currentThread()) has a pending interrupt request (
true) or not (false). | |||||||||||
Returns
true if the receiver has already been started and
still runs code (hasn't died yet). | |||||||||||
Returns a
boolean indicating whether the receiver is a
daemon Thread (true) or not (false) A
daemon Thread only runs as long as there are non-daemon Threads running. | |||||||||||
Returns a
boolean indicating whether the receiver has a
pending interrupt request (true) or not (
false) | |||||||||||
Blocks the current Thread (
Thread.currentThread()) until
the receiver finishes its execution and dies. | |||||||||||
Blocks the current Thread (
Thread.currentThread()) until
the receiver finishes its execution and dies or the specified timeout
expires, whatever happens first. | |||||||||||
Blocks the current Thread (
Thread.currentThread()) until
the receiver finishes its execution and dies or the specified timeout
expires, whatever happens first. | |||||||||||
This method is deprecated.
Used with deprecated method suspend()
| |||||||||||
Calls the
run() method of the Runnable object the receiver
holds. | |||||||||||
Set the context ClassLoader for the receiver.
| |||||||||||
Set if the receiver is a daemon Thread or not.
| |||||||||||
Sets the default uncaught exception handler. | |||||||||||
Sets the name of the receiver.
| |||||||||||
Sets the priority of the receiver.
| |||||||||||
Sets the default uncaught exception handler. | |||||||||||
Causes the thread which sent this message to sleep an interval of time
(given in milliseconds).
| |||||||||||
Causes the thread which sent this message to sleep an interval of time
(given in milliseconds).
| |||||||||||
Starts the new Thread of execution.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
This method is deprecated.
May cause deadlocks.
| |||||||||||
Returns a string containing a concise, human-readable description of the
receiver.
| |||||||||||
Causes the thread which sent this message to yield execution to another
Thread that is ready to run.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.Runnable
| |||||||||||
The maximum priority value allowed for a thread.
The minimum priority value allowed for a thread.
The normal (default) priority value assigned to threads.
Constructs a new Thread with no runnable object and a newly generated name. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor.
Constructs a new Thread with a runnable object and a newly generated name. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor.
| runnable | a java.lang.Runnable whose method run will
be executed by the new Thread |
|---|
Constructs a new Thread with a runnable object and name provided. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor.
| runnable | a java.lang.Runnable whose method run will
be executed by the new Thread |
|---|---|
| threadName | Name for the Thread being created |
Constructs a new Thread with no runnable object and the name provided. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor.
| threadName | Name for the Thread being created |
|---|
Constructs a new Thread with a runnable object and a newly generated name. The new Thread will belong to the ThreadGroup passed as parameter.
| group | ThreadGroup to which the new Thread will belong |
|---|---|
| runnable | a java.lang.Runnable whose method run will
be executed by the new Thread |
| SecurityException | if group.checkAccess() fails
with a SecurityException |
|---|---|
| IllegalThreadStateException | if group.destroy() has
already been done |
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter.
| group | ThreadGroup to which the new Thread will belong |
|---|---|
| runnable | a java.lang.Runnable whose method run will
be executed by the new Thread |
| threadName | Name for the Thread being created |
| SecurityException | if group.checkAccess() fails
with a SecurityException |
|---|---|
| IllegalThreadStateException | if group.destroy() has
already been done |
Constructs a new Thread with no runnable object, the given name and belonging to the ThreadGroup passed as parameter.
| group | ThreadGroup to which the new Thread will belong |
|---|---|
| threadName | Name for the Thread being created |
| SecurityException | if group.checkAccess() fails
with a SecurityException |
|---|---|
| IllegalThreadStateException | if group.destroy() has
already been done |
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter.
| group | ThreadGroup to which the new Thread will belong |
|---|---|
| runnable | a java.lang.Runnable whose method run will
be executed by the new Thread |
| threadName | Name for the Thread being created |
| stackSize | Platform dependent stack size |
| SecurityException | if group.checkAccess() fails
with a SecurityException |
|---|---|
| IllegalThreadStateException | if group.destroy() has
already been done |
Returns the number of active threads in the running thread's ThreadGroup and its subgroups.
This method is used for operations that require approval from a SecurityManager. If there's none installed, this method is a no-op. If there's a SecurityManager installed , checkAccess(Thread) is called for that SecurityManager.
This method is deprecated.The results of this call were never well defined. To make things worse, it would depend if the Thread was suspended or not, and suspend was deprecated too.
Returns the number of stack frames in this thread.
Returns the instance of Thread that corresponds to the running Thread which calls this method.
currentThread()
This method is deprecated.Not implemented.
Destroys the receiver without any monitor cleanup.
Prints a text representation of the stack for this Thread.
Copies an array with all Threads which are in the same ThreadGroup as the
receiver - and subgroups - into the array threads passed
as parameter. If the array passed as parameter is too small no exception
is thrown - the extra elements are simply not copied.
| threads | array into which the Threads will be copied |
|---|
| SecurityException | if the installed SecurityManager fails checkAccess(Thread) |
|---|
Returns the stack traces of all the currently live threads and puts them into the given map.
| SecurityException | if the current SecurityManager fails the checkPermission(java.security.Permission) call. |
|---|
Returns the context ClassLoader for the receiver.
If the conditions
RuntimePermission("getClassLoader") is performed first.| SecurityException | If aforementioned security check fails. |
|---|
Returns the default exception handler that's executed when uncaught exception terminates a thread.
null if
none exists.
Returns the thread's identifier. The ID is a positive long
generated on thread creation, is unique to the thread and doesn't change
during the life of the thread; the ID may be reused after the thread has
been terminated.
Returns the name of the receiver.
Returns the priority of the receiver.
int)Returns the current stack trace of the thread.
The RuntimePermission("getStackTrace") is checked before
returning a result.
| SecurityException | if the current SecurityManager fails the checkPermission(java.security.Permission) call. |
|---|
Returns the current state of the thread for monitoring purposes.
Returns the ThreadGroup to which the receiver belongs
Returns the thread's uncaught exception handler. If not explicitly set,
then the ThreadGroup's handler is returned. If the thread is terminated,
then null is returned.
null.Returns whether the current thread has a monitor lock on the specified object.
| object | the object to test for the monitor lock |
|---|
Posts an interrupt request to the receiver.
| SecurityException | if checkAccess() fails
with a SecurityException |
|---|
Returns a boolean indicating whether the current Thread (
currentThread()) has a pending interrupt request (
true) or not (false). It also has the
side-effect of clearing the flag.
booleanReturns true if the receiver has already been started and
still runs code (hasn't died yet). Returns false either if
the receiver hasn't been started yet or if it has already started and run
to completion and died.
booleanReturns a boolean indicating whether the receiver is a
daemon Thread (true) or not (false) A
daemon Thread only runs as long as there are non-daemon Threads running.
When the last non-daemon Thread ends, the whole program ends no matter if
it had daemon Threads still running or not.
booleanReturns a boolean indicating whether the receiver has a
pending interrupt request (true) or not (
false)
booleanBlocks the current Thread (Thread.currentThread()) until
the receiver finishes its execution and dies.
| InterruptedException | if interrupt() was called for
the receiver while it was in the join() call |
|---|
Blocks the current Thread (Thread.currentThread()) until
the receiver finishes its execution and dies or the specified timeout
expires, whatever happens first.
| millis | The maximum time to wait (in milliseconds). |
|---|---|
| nanos | Extra nanosecond precision |
| InterruptedException | if interrupt() was called for
the receiver while it was in the join() call |
|---|
Blocks the current Thread (Thread.currentThread()) until
the receiver finishes its execution and dies or the specified timeout
expires, whatever happens first.
| millis | The maximum time to wait (in milliseconds). |
|---|
| InterruptedException | if interrupt() was called for
the receiver while it was in the join() call |
|---|
This method is deprecated.Used with deprecated method suspend()
This is a no-op if the receiver was never suspended, or suspended and already resumed. If the receiver is suspended, however, makes it resume to the point where it was when it was suspended.
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|
Calls the run() method of the Runnable object the receiver
holds. If no Runnable is set, does nothing.
Set the context ClassLoader for the receiver.
The RuntimePermission("setContextClassLoader")
is checked prior to setting the handler.
| cl | The context ClassLoader |
|---|
| SecurityException | if the current SecurityManager fails the checkPermission call. |
|---|
Set if the receiver is a daemon Thread or not. This can only be done before the Thread starts running.
| isDaemon | A boolean indicating if the Thread should be daemon or not |
|---|
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|
Sets the default uncaught exception handler.
The RuntimePermission("setDefaultUncaughtExceptionHandler")
is checked prior to setting the handler.
| handler | The handler to set or null. |
|---|
| SecurityException | if the current SecurityManager fails the checkPermission call. |
|---|
Sets the name of the receiver.
| threadName | new name for the Thread |
|---|
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|
Sets the priority of the receiver. Note that the final priority set may not be the parameter that was passed - it will depend on the receiver's ThreadGroup. The priority cannot be set to be higher than the receiver's ThreadGroup's maxPriority().
| priority | new priority for the Thread |
|---|
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|---|
| IllegalArgumentException | if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY |
Sets the default uncaught exception handler.
| handler | The handler to set or null. |
|---|
| SecurityException | if the current SecurityManager fails the checkAccess call. |
|---|
Causes the thread which sent this message to sleep an interval of time (given in milliseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.
| time | The time to sleep in milliseconds. |
|---|---|
| nanos | Extra nanosecond precision |
| InterruptedException | if interrupt() was called for
this Thread while it was sleeping |
|---|
Causes the thread which sent this message to sleep an interval of time (given in milliseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.
| time | The time to sleep in milliseconds. |
|---|
| InterruptedException | if interrupt() was called for
this Thread while it was sleeping |
|---|
Starts the new Thread of execution. The run() method of
the receiver will be called by the receiver Thread itself (and not the
Thread calling start()).
| IllegalThreadStateException | Unspecified in the Java language specification |
|---|
This method is deprecated.No replacement.
Requests the receiver Thread to stop and throw ThreadDeath. The Thread is resumed if it was suspended and awakened if it was sleeping, so that it can proceed to throw ThreadDeath.
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|
This method is deprecated.No replacement.
Requests the receiver Thread to stop and throw the
throwable(). The Thread is resumed if it was suspended
and awakened if it was sleeping, so that it can proceed to throw the
throwable().
| throwable | Throwable object to be thrown by the Thread |
|---|
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|---|
| NullPointerException | if throwable() is
null |
This method is deprecated.May cause deadlocks.
This is a no-op if the receiver is suspended. If the receiver
isAlive() however, suspended it until
resume() is sent to it. Suspend requests are not queued,
which means that N requests are equivalent to just one - only one resume
request is needed in this case.
| SecurityException | if checkAccess() fails with a
SecurityException |
|---|
Returns a string containing a concise, human-readable description of the receiver.
Causes the thread which sent this message to yield execution to another Thread that is ready to run. The actual scheduling is implementation-dependent.