Some Useful Methods
Home ] Up ] What is a Thread? ] Thread States ] Daemon Threads ] Thread Operations ] [ Some Useful Methods ] Deprecated Methods ]

 

 

Here are some useful methods provided by the Thread class:

Method Description
public Thread()
Constructs a new Thread object, with an automatically generated name
public Thread(String name)
Constructs a new Thread object, with the specified name
public Thread(Runnable target)
Constructs a new Thread object, with the associated Runnable object and an automatically generated name
public Thread(Runnable target, 
              String name)
Constructs a new Thread object, with the associated Runnable object and the specified name.
public static Thread 
              currentThread()
Returns a reference to the currently executing thread object.
public static void 
              dumpStack()
Prints a stack trace of the current thread. This method is used only for debugging
public final String getName()
Returns this thread's name.
public void interrupt()
Interrupts this thread.
public final boolean 
               isAlive()
Tests if this thread is alive. A thread is alive if it has been started and has not yet died.
public final void setName(
               String name)
Changes the name of this thread to be equal to the argument name.
public static void sleep(
               long millis)
throws InterruptedException
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
public static void sleep(
               long millis, 
               int nanos) 
throws InterruptedException
Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds.
public synchronized void start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
public static void yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
 
The page was last updated February 19, 2008