Thread class methods

In this tutorial, we will learn about Thread class methods. In the last tutorial, we already saw two thread class methods run() and start() method. There are a lot of other methods in Thread class. Check this following list.

Method Description
public void start() This method is used to start the execution of the thread.
public void run() This method is used to describe the action in the thread.
public final void setName(String name) This method is used to set the name of the thread.
public final void setPriority(int priority) This method is used to set the priority of the thread.
public final void join(long milliseconds) This method is used to block the current thread for specified milliseconds until another thread completes its execution or specified milliseconds passed
public void interrupt() This method is used to interrupt a thread.
public void stop() This method is used to stop a thread.
public void suspend() This method is used to suspend a thread.
public void resume() This method is used to resume the suspended thread.
public final boolean isAlive() This method is used to check whether a thread is alive or not.
public static void yield() This method is used to block currently running thread and allow other threads with the same property to run temporarily.
public static void sleep(long milliseconds) This is used to block a thread for specific milliseconds.
public static boolean holdsLock(Object x) This method will return true if the current thread holds the lock on the given Object.
public static Thread currentThread() This method returns the reference of currently running thread.
public static void dumpStack() This method prints the stack trace of currently running thread.
public void destroy() This method is used to destroy the thread group.
Spread the love
Scroll to Top
×