DthingApi
|
Classes | |
interface | UncaughtExceptionHandler |
Public Member Functions | |
Thread () | |
Thread (Runnable runnable) | |
Thread (Runnable runnable, String threadName) | |
Thread (String threadName) | |
long | getId () |
final String | getName () |
final int | getPriority () |
UncaughtExceptionHandler | getUncaughtExceptionHandler () |
native void | interrupt () |
final native boolean | isAlive () |
native boolean | isInterrupted () |
final void | join () throws InterruptedException |
final void | join (long millis) throws InterruptedException |
final void | join (long millis, int nanos) throws InterruptedException |
void | run () |
final void | setName (String threadName) |
final native void | setPriority (int priority) |
void | setUncaughtExceptionHandler (UncaughtExceptionHandler handler) |
synchronized native void | start () |
String | toString () |
Static Public Member Functions | |
static native int | activeCount () |
static native Thread | currentThread () |
static void | dumpStack () |
static UncaughtExceptionHandler | getDefaultUncaughtExceptionHandler () |
static native boolean | interrupted () |
static void | setDefaultUncaughtExceptionHandler (UncaughtExceptionHandler handler) |
static void | sleep (long time) throws InterruptedException |
static native void | sleep (long millis, int nanos) throws InterruptedException |
static native void | yield () |
static native boolean | holdsLock (Object object) |
Static Public Attributes | |
static final int | STATE_NEW = 0 |
static final int | STATE_RUNNABLE = 1 |
static final int | STATE_BLOCKED = 2 |
static final int | STATE_WAITING = 3 |
static final int | STATE_TIMED_WAITING = 4 |
static final int | STATE_TERMINATED = 5 |
static final int | MAX_PRIORITY = 10 |
static final int | MIN_PRIORITY = 1 |
static final int | NORM_PRIORITY = 5 |
A
is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables. Each virtual machine instance has at least one main
running when it is started; typically, there are several others for housekeeping. The application might decide to launch additional
s for specific purposes.
s 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
s to cooperate.
There are basically two main ways of having a
execute application code. One is providing a new class that extends
and overriding its run() method. The other is providing a new
instance with a Runnable object during its creation. In both cases, the start() method must be called to actually execute the new
.
Each
has an integer priority that basically determines the amount of CPU time the
gets. It can be set using the setPriority(int) method. A
can also be made a daemon, which makes it run in the background. The latter also affects VM termination behavior: the VM does not terminate automatically as long as there are non-daemon threads running.
|
inline |
Constructs a new
with no
object and a newly generated name. The new
will belong to the same
as the
calling this constructor.
|
inline |
Constructs a new
with a
object and a newly generated name. The new
will belong to the same
as the
calling this constructor.
runnable | a Runnable run will be executed by the new |
Constructs a new
with a
object and name provided. The new
will belong to the same
as the
calling this constructor.
runnable | a Runnable run will be executed by the new |
threadName | the name for the being created |
|
inline |
Constructs a new
with no
object and the name provided. The new
will belong to the same
as the
calling this constructor.
threadName | the name for the being created |
|
static |
|
static |
|
inlinestatic |
Prints to the standard error stream a text representation of the current stack for this Thread.
|
inlinestatic |
Returns the default exception handler that's executed when uncaught exception terminates a thread.
null
if none exists.
|
inline |
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 lifetime of the thread; the ID may be reused after the thread has been terminated.
|
inline |
|
inline |
|
inline |
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.
|
static |
Indicates whether the current Thread has a monitor lock on the specified object.
object | the object to test for the monitor lock |
native void java.lang.Thread.interrupt | ( | ) |
Posts an interrupt request to this
. The behavior depends on the state of this
:
|
static |
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.
boolean
indicating the interrupt status final native boolean java.lang.Thread.isAlive | ( | ) |
Returns 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.
boolean
indicating the liveness of the Thread native boolean java.lang.Thread.isInterrupted | ( | ) |
Returns a boolean
indicating whether the receiver has a pending interrupt request (true
) or not ( false
)
boolean
indicating the interrupt status
|
inline |
Blocks 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 |
|
inline |
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 |
|
inline |
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 |
|
inline |
Calls the run()
method of the Runnable object the receiver holds. If no Runnable is set, does nothing.
Implements java.lang.Runnable.
|
inlinestatic |
Sets the default uncaught exception handler. This handler is invoked in case any Thread dies due to an unhandled exception.
handler | The handler to set or null. |
|
inline |
Sets the name of the Thread.
threadName | the new name for the Thread |
final native void java.lang.Thread.setPriority | ( | int | priority | ) |
Sets the priority of the Thread. 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 |
IllegalArgumentException | if the new priority is greater than Thread.MAX_PRIORITY or less than Thread.MIN_PRIORITY |
|
inline |
Sets the uncaught exception handler. This handler is invoked in case this Thread dies due to an unhandled exception.
handler | The handler to set or null . |
|
inlinestatic |
Causes the thread which sent this message to sleep for the given 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 |
|
static |
Causes the thread which sent this message to sleep for the given interval of time (given in milliseconds and nanoseconds). The precision is not guaranteed - the Thread may sleep more or less than requested.
millis | The time to sleep in milliseconds. |
nanos | Extra nanosecond precision |
InterruptedException | if interrupt() was called for this Thread while it was sleeping |
synchronized native void java.lang.Thread.start | ( | ) |
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 | if the Thread has been started before |
|
inline |
|
static |
|
static |
The maximum priority value allowed for a thread.
|
static |
The minimum priority value allowed for a thread.
|
static |
The normal (default) priority value assigned to threads.
|
static |
The thread is blocked and waiting for a lock.
|
static |
The thread has been created, but has never been started.
|
static |
The thread may be run.
|
static |
The thread has been terminated.
|
static |
The thread is waiting for a specified amount of time.
|
static |
The thread is waiting.