The documented methods must be implemented to support other provided class implementations in this package. A Thread is a unit of concurrent execution in Java. 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. When a Java program starts executing there is an implicit Thread (called "main") which is automatically created by the VM. This Thread belongs to a ThreadGroup (also called "main") which is automatically created by the bootstrap sequence by the VM as well.
Public Member Functions | |
Thread () | |
Constructs a new Thread with no runnable object and a newly generated name. | |
Thread (Runnable runnable) | |
Constructs a new Thread with a runnable object and a newly generated name. | |
Thread (Runnable runnable, String threadName) | |
Constructs a new Thread with a runnable object and name provided. | |
Thread (String threadName) | |
Constructs a new Thread with no runnable object and the name provided. | |
Thread (ThreadGroup group, Runnable runnable) | |
Constructs a new Thread with a runnable object and a newly generated name. | |
Thread (ThreadGroup group, Runnable runnable, String threadName, long stack) | |
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter. | |
Thread (ThreadGroup group, Runnable runnable, String threadName) | |
Constructs a new Thread with a runnable object, the given name and belonging to the ThreadGroup passed as parameter. | |
Thread (ThreadGroup group, String threadName) | |
Constructs a new Thread with no runnable object, the given name and belonging to the ThreadGroup passed as parameter. | |
final void | checkAccess () |
This method is used for operations that require approval from a SecurityManager. | |
int | countStackFrames () |
Returns the number of stack frames in this thread. | |
void | destroy () |
Destroys the receiver without any monitor cleanup. | |
ClassLoader | getContextClassLoader () |
Returns the context ClassLoader for the receiver. | |
final String | getName () |
Answers the name of the receiver. | |
final int | getPriority () |
Answers the priority of the receiver. | |
final ThreadGroup | getThreadGroup () |
Answers the ThreadGroup to which the receiver belongs. | |
void | interrupt () |
Posts an interrupt request to the receiver. | |
final boolean | isAlive () |
Answers true if the receiver has already been started and still runs code (hasn't died yet). | |
final boolean | isDaemon () |
Answers 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. | |
boolean | isInterrupted () |
Answers a boolean indicating whether the receiver has a pending interrupt request (true ) or not ( false ). | |
final void | join () throws InterruptedException |
Blocks the current Thread (Thread.currentThread() ) until the receiver finishes its execution and dies. | |
final void | join (long timeoutInMilliseconds) throws InterruptedException |
Blocks the current Thread (Thread.currentThread() ) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first. | |
final void | join (long timeoutInMilliseconds, int nanos) throws InterruptedException |
Blocks the current Thread (Thread.currentThread() ) until the receiver finishes its execution and dies or the specified timeout expires, whatever happens first. | |
final void | resume () |
This is a no-op if the receiver was never suspended, or suspended and already resumed. | |
void | run () |
Calls the run() method of the Runnable object the receiver holds. | |
void | setContextClassLoader (ClassLoader cl) |
Set the context ClassLoader for the receiver. | |
final void | setDaemon (boolean isDaemon) |
Set if the receiver is a daemon Thread or not. | |
final void | setName (String threadName) |
Sets the name of the receiver. | |
final void | setPriority (int priority) |
Sets the priority of the receiver. | |
void | start () |
Starts the new Thread of execution. | |
final void | stop () |
Requests the receiver Thread to stop and throw ThreadDeath. | |
final void | stop (Throwable throwable) |
Requests the receiver Thread to stop and throw the throwable() . | |
final void | suspend () |
This is a no-op if the receiver is suspended. | |
String | toString () |
Answers a string containing a concise, human-readable description of the receiver. | |
Static Public Member Functions | |
static int | activeCount () |
Returns the number of active threads in the running thread's ThreadGroup. | |
static Thread | currentThread () |
Answers the instance of Thread that corresponds to the running Thread which calls this method. | |
static void | dumpStack () |
Prints a text representation of the stack for this Thread. | |
static int | enumerate (Thread[] threads) |
Copies an array with all Threads which are in the same ThreadGroup as the receiver - and subgroups - into the array threads passed as parameter. | |
static boolean | interrupted () |
Answers a boolean indicating whether the current Thread ( currentThread() ) has a pending interrupt request ( true ) or not (false ). | |
static void | sleep (long time) throws InterruptedException |
Causes the thread which sent this message to sleep an interval of time (given in milliseconds). | |
static void | sleep (long time, int nanos) throws InterruptedException |
Causes the thread which sent this message to sleep an interval of time (given in milliseconds). | |
static void | yield () |
Causes the thread which sent this message to yield execution to another Thread that is ready to run. | |
static boolean | holdsLock (Object object) |
Returns whether the current thread has a monitor lock on the specified object. | |
Static Public Attributes | |
static final int | MAX_PRIORITY = 10 |
static final int | MIN_PRIORITY = 1 |
static final int | NORM_PRIORITY = 5 |
Package Functions | |
Object | getThreadLocal (ThreadLocal local) |
A sample implementation of this method is provided by the reference implementation. | |
void | setThreadLocal (ThreadLocal local, Object value) |
A sample implementation of this method is provided by the reference implementation. | |
Package Attributes | |
Object | slot1 |
Object | slot2 |
Object | slot3 |
|
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.
|
|
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.
|
|
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.
|
|
Constructs a new Thread with a runnable object and a newly generated name. The new Thread will belong 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.
|
|
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.
|
|
Returns the number of active threads in the running thread's ThreadGroup.
|
|
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 ,
|
|
Returns the number of stack frames in this thread.
|
|
Answers the instance of Thread that corresponds to the running Thread which calls this method.
|
|
Destroys the receiver without any monitor cleanup. 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 If the array passed as parameter is too small no exception is thrown - the extra elements are simply not copied.
|
|
Returns the context ClassLoader for the receiver.
|
|
Answers the name of the receiver.
|
|
Answers the priority of the receiver.
|
|
Answers the ThreadGroup to which the receiver belongs.
|
|
A sample implementation of this method is provided by the reference implementation. It must be included, as it is called by ThreadLocal.get() and InheritableThreadLocal.get(). Return the value associated with the ThreadLocal in the receiver
|
|
Posts an interrupt request to the receiver.
|
|
Answers a It also has the side-effect of clearing the flag.
|
|
Answers
Answers
|
|
Answers a When the last non-daemon Thread ends, the whole program ends no matter if it had daemon Threads still running or not.
|
|
Answers a
|
|
Blocks the current Thread (
|
|
Blocks the current Thread (
|
|
Blocks the current Thread (
|
|
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.
|
|
Calls the If no Runnable is set, does nothing.
|
|
Set the context ClassLoader for the receiver.
|
|
Set if the receiver is a daemon Thread or not. This can only be done before the Thread starts running.
|
|
Sets the name of the receiver.
|
|
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().
|
|
A sample implementation of this method is provided by the reference implementation.
It must be included, as it is called by ThreadLocal.set() and InheritableThreadLocal.set(). Set the value associated with the ThreadLocal in the receiver to be
|
|
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.
|
|
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.
|
|
Starts the new Thread of execution.
The
|
|
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.
|
|
Requests the receiver Thread to stop and throw the
The Thread is resumed if it was suspended and awakened if it was sleeping, so that it can proceed to throw the
|
|
This is a no-op if the receiver is suspended.
If the receiver
|
|
Answers 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. |
|
Returns whether the current thread has a monitor lock on the specified object.
|