Thread

Name

Thread

Synopsis

Description

The Thread class encapsulates all of the information about a single thread of control running in a Java environment. Thread objects are used to control threads in a multithreaded program.

The execution of Java code is always under the control of a Thread object. The Thread class provides a static method called currentThread() that can be used to get a reference to the Thread object that controls the current thread of execution.

In order for a Thread object to be useful, it must be associated with a method that it is supposed to run. Java provides two ways of associating a Thread object with a method:

After a thread is started, it dies when one of the following things happens:

Class Summary

public class java.lang.Thread extends java.lang.Object implements java.lang.Runnable {
 // Constants public final static int MAX_PRIORITY;
public final static int MIN_PRIORITY;
public final static int NORM_PRIORITY; // Constructors public Thread();
public Thread(Runnable target);
public Thread(Runnable target, String name);
public Thread(String name);
public Thread(ThreadGroup group, Runnable target);
public Thread(ThreadGroup group, Runnable target, String name);
public Thread(ThreadGroup group, String name); // Class Methods public static int activeCount();
public static native Thread currentThread();
public static void dumpStack();
public static int enumerate(Thread tarray[]);
public static boolean interrupted();
public static native void sleep(long millis);
public static void sleep(long millis, int nanos);
public static native void yield(); // Instance Methods public void checkAccess();
public native int countStackFrames();
public void destroy();
public final String getName();
public final int getPriority();
public final ThreadGroup getThreadGroup();
public void interrupt();
public final native boolean isAlive();
public final boolean isDaemon();
public boolean isInterrupted();
public final void join();
public final synchronized void join(long millis);
public final synchronized void join(long millis, int nanos);
public final void resume();
public void run();
public final void setDaemon(boolean on);
public final void setName(String name);
public final void setPriority(int newPriority);
public synchronized native void start();
public final void stop();
public final synchronized void stop(Throwable o);
public final void suspend();
public String toString();
}

Constants

MAX_PRIORITY

public final static int MAX_PRIORITY = 10

MIN_PRIORITY

public final static int MIN_PRIORITY = 1

NORM_PRIORITY

public final static int NORM_PRIORITY = 5

Constructors

Thread

public Thread()

public Thread(String name)

public Thread(ThreadGroup group, Runnable target)

public Thread(ThreadGroup group, Runnable target, String name)

public Thread(ThreadGroup group, String name)

Class Methods

activeCount

public static int activeCount()

currentThread

public static native Thread currentThread()

dumpStack

public static void dumpStack()

enumerate

public static int enumerate(Thread tarray[])

interrupted

public static boolean interrupted()

sleep

public static native void sleep(long millis)

public static void sleep(long millis, int nanos)

yield

public static native void yield()

Instance Methods

checkAccess

public void checkAccess()

countStackFrames

public native int countStackFrames()

destroy

public void destroy()

getName

public final String getName()

getPriority

public final int getPriority()

getThreadGroup

public final ThreadGroup getThreadGroup()

interrupt

public void interrupt()

isAlive

public final native boolean isAlive()

isDaemon

public final boolean isDaemon()

isInterrupted

public boolean isInterrupted()

join

public final void join()

public final synchronized void join(long millis)

public final synchronized void join(long millis, int nanos)

resume

public final void resume()

run

public void run()

setDaemon

public final void setDaemon(boolean on)

setName

public final void setName(String name)

setPriority

public final void setPriority(int newPriority)

start

public synchronized native void start()

stop

public final void stop()

public final synchronized void stop(Throwable o)

suspend

public final void suspend()

toString

public String toString()

Inherited Methods

Method Inherited From Method Inherited From
clone() Object equals(Object) Object
finalize() Object getClass() Object
hashCode() Object notify() Object
notifyAll() Object wait() Object
wait(long) Object wait(long, int) Object

See Also

Exceptions; Object; Runnable; SecurityManager; ThreadGroup; Threads 8