Modifier and Type | Field and Description |
---|---|
static int |
MAX_PRIORITY
The maximum priority that a thread can have.
|
static int |
MIN_PRIORITY
The minimum priority that a thread can have.
|
static int |
NORM_PRIORITY
The default priority that is assigned to a thread.
|
Constructor and Description |
---|
Thread()
Allocates a new Thread object.
|
Thread(Runnable target)
Allocates a new Thread object with a specific target object whose run method is called.
|
Thread(Runnable target,
String name)
Allocates a new Thread object with the given target and name.
|
Thread(String name)
Allocates a new Thread object with the given name.
|
Modifier and Type | Method and Description |
---|---|
static int |
activeCount()
Returns the current number of active threads in the virtual machine.
|
static Thread |
currentThread()
Returns a reference to the currently executing Thread object.
|
String |
getName()
Returns this thread's name.
|
int |
getPriority()
Returns this thread's priority.
|
StackTraceElement[] |
getStackTrace() |
void |
interrupt()
Interrupts this thread.
|
boolean |
isAlive()
Tests if this thread is alive.
|
void |
join()
Waits for this thread to die.
|
void |
run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
|
void |
setPriority(int newPriority)
Changes the priority of this thread.
|
static void |
sleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
|
void |
start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
|
String |
toString()
Returns a string representation of this thread, including the thread's name and priority.
|
static void |
yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
|
public static final int MAX_PRIORITY
public static final int MIN_PRIORITY
public static final int NORM_PRIORITY
public Thread()
public Thread(Runnable target)
public Thread(Runnable target, String name)
public Thread(String name)
public static int activeCount()
public static Thread currentThread()
public final String getName()
public final int getPriority()
public void interrupt()
public final boolean isAlive()
public final void join() throws InterruptedException
InterruptedException
public void run()
public final void setPriority(int newPriority)
public static void sleep(long millis) throws InterruptedException
InterruptedException
public void start()
public String toString()
public static void yield()
public StackTraceElement[] getStackTrace()