Thread (Java Platform SE 7 ) (original) (raw)

Modifier and Type

Method and Description

static int

**[activeCount](../../java/lang/Thread.html#activeCount%28%29)**()

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

void

**[checkAccess](../../java/lang/Thread.html#checkAccess%28%29)**()

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

protected [Object](../../java/lang/Object.html "class in java.lang")

**[clone](../../java/lang/Thread.html#clone%28%29)**()

Throws CloneNotSupportedException as a Thread can not be meaningfully cloned.

int

**[countStackFrames](../../java/lang/Thread.html#countStackFrames%28%29)**()

Deprecated.

The definition of this call depends on suspend(), which is deprecated. Further, the results of this call were never well-defined.

static [Thread](../../java/lang/Thread.html "class in java.lang")

**[currentThread](../../java/lang/Thread.html#currentThread%28%29)**()

Returns a reference to the currently executing thread object.

void

**[destroy](../../java/lang/Thread.html#destroy%28%29)**()

Deprecated.

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](../../java/lang/Thread.html#dumpStack%28%29)**()

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

static int

**[enumerate](../../java/lang/Thread.html#enumerate%28java.lang.Thread[]%29)**([Thread](../../java/lang/Thread.html "class in java.lang")[] tarray)

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

static [Map](../../java/util/Map.html "interface in java.util")<[Thread](../../java/lang/Thread.html "class in java.lang"),[StackTraceElement](../../java/lang/StackTraceElement.html "class in java.lang")[]>

**[getAllStackTraces](../../java/lang/Thread.html#getAllStackTraces%28%29)**()

Returns a map of stack traces for all live threads.

[ClassLoader](../../java/lang/ClassLoader.html "class in java.lang")

**[getContextClassLoader](../../java/lang/Thread.html#getContextClassLoader%28%29)**()

Returns the context ClassLoader for this Thread.

static [Thread.UncaughtExceptionHandler](../../java/lang/Thread.UncaughtExceptionHandler.html "interface in java.lang")

**[getDefaultUncaughtExceptionHandler](../../java/lang/Thread.html#getDefaultUncaughtExceptionHandler%28%29)**()

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

long

**[getId](../../java/lang/Thread.html#getId%28%29)**()

Returns the identifier of this Thread.

[String](../../java/lang/String.html "class in java.lang")

**[getName](../../java/lang/Thread.html#getName%28%29)**()

Returns this thread's name.

int

**[getPriority](../../java/lang/Thread.html#getPriority%28%29)**()

Returns this thread's priority.

[StackTraceElement](../../java/lang/StackTraceElement.html "class in java.lang")[]

**[getStackTrace](../../java/lang/Thread.html#getStackTrace%28%29)**()

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

[Thread.State](../../java/lang/Thread.State.html "enum in java.lang")

**[getState](../../java/lang/Thread.html#getState%28%29)**()

Returns the state of this thread.

[ThreadGroup](../../java/lang/ThreadGroup.html "class in java.lang")

**[getThreadGroup](../../java/lang/Thread.html#getThreadGroup%28%29)**()

Returns the thread group to which this thread belongs.

[Thread.UncaughtExceptionHandler](../../java/lang/Thread.UncaughtExceptionHandler.html "interface in java.lang")

**[getUncaughtExceptionHandler](../../java/lang/Thread.html#getUncaughtExceptionHandler%28%29)**()

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

static boolean

**[holdsLock](../../java/lang/Thread.html#holdsLock%28java.lang.Object%29)**([Object](../../java/lang/Object.html "class in java.lang") obj)

Returns

true

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

void

**[interrupt](../../java/lang/Thread.html#interrupt%28%29)**()

Interrupts this thread.

static boolean

**[interrupted](../../java/lang/Thread.html#interrupted%28%29)**()

Tests whether the current thread has been interrupted.

boolean

**[isAlive](../../java/lang/Thread.html#isAlive%28%29)**()

Tests if this thread is alive.

boolean

**[isDaemon](../../java/lang/Thread.html#isDaemon%28%29)**()

Tests if this thread is a daemon thread.

boolean

**[isInterrupted](../../java/lang/Thread.html#isInterrupted%28%29)**()

Tests whether this thread has been interrupted.

void

**[join](../../java/lang/Thread.html#join%28%29)**()

Waits for this thread to die.

void

**[join](../../java/lang/Thread.html#join%28long%29)**(long millis)

Waits at most millis milliseconds for this thread to die.

void

**[join](../../java/lang/Thread.html#join%28long,%20int%29)**(long millis, int nanos)

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

void

**[resume](../../java/lang/Thread.html#resume%28%29)**()

void

**[run](../../java/lang/Thread.html#run%28%29)**()

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

void

**[setContextClassLoader](../../java/lang/Thread.html#setContextClassLoader%28java.lang.ClassLoader%29)**([ClassLoader](../../java/lang/ClassLoader.html "class in java.lang") cl)

Sets the context ClassLoader for this Thread.

void

**[setDaemon](../../java/lang/Thread.html#setDaemon%28boolean%29)**(boolean on)

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

static void

**[setDefaultUncaughtExceptionHandler](../../java/lang/Thread.html#setDefaultUncaughtExceptionHandler%28java.lang.Thread.UncaughtExceptionHandler%29)**([Thread.UncaughtExceptionHandler](../../java/lang/Thread.UncaughtExceptionHandler.html "interface in java.lang") 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.

void

**[setName](../../java/lang/Thread.html#setName%28java.lang.String%29)**([String](../../java/lang/String.html "class in java.lang") name)

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

void

**[setPriority](../../java/lang/Thread.html#setPriority%28int%29)**(int newPriority)

Changes the priority of this thread.

void

**[setUncaughtExceptionHandler](../../java/lang/Thread.html#setUncaughtExceptionHandler%28java.lang.Thread.UncaughtExceptionHandler%29)**([Thread.UncaughtExceptionHandler](../../java/lang/Thread.UncaughtExceptionHandler.html "interface in java.lang") eh)

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

static void

**[sleep](../../java/lang/Thread.html#sleep%28long%29)**(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 void

**[sleep](../../java/lang/Thread.html#sleep%28long,%20int%29)**(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.

void

**[start](../../java/lang/Thread.html#start%28%29)**()

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

void

**[stop](../../java/lang/Thread.html#stop%28%29)**()

Deprecated.

This method is 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 uncheckedThreadDeath 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, seeWhy are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

void

**[stop](../../java/lang/Thread.html#stop%28java.lang.Throwable%29)**([Throwable](../../java/lang/Throwable.html "class in java.lang") obj)

Deprecated.

This method is inherently unsafe. See stop() for details. An additional danger of this method is that it may be used to generate exceptions that the target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw, were it not for this method). For more information, seeWhy are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

void

**[suspend](../../java/lang/Thread.html#suspend%28%29)**()

Deprecated.

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, seeWhy are Thread.stop, Thread.suspend and Thread.resume Deprecated?.

[String](../../java/lang/String.html "class in java.lang")

**[toString](../../java/lang/Thread.html#toString%28%29)**()

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

static void

**[yield](../../java/lang/Thread.html#yield%28%29)**()

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