List of Thread class methods in Java

On this page, you will get the list of some frequently used methods of class Thread in Java that makes the application simple and reliable.

Modifier and Type Method Name Description
void start() Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
static void sleep(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.
void setPriority(int newPriority) Changes the priority of this thread.
void setName(String name) Changes the name of this thread to be equal to the argument name.
void setDaemon(boolean on) Marks this thread as either a daemon thread or a user thread.
void setContextClassLoader(ClassLoader cl) Sets the context ClassLoader for this Thread.
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 join() Waits for this thread to die.
void join(long millis) Waits at most millis milliseconds for this thread to die.
boolean isInterrupted() Tests whether this thread has been interrupted.
boolean isDaemon() Tests if this thread is a daemon thread.
boolean isAlive() Tests if this thread is alive.
static boolean holdsLock(Object obj) Returns true if and only if the current thread holds the monitor lock on the specified object.
Thread.State getState() Returns the state of this thread.
StackTraceElement[] getStackTrace() Returns an array of stack trace elements representing the stack dump of this thread.
int getPriority() Returns this thread’s priority.
String getName() Returns this thread’s name.
long getId() Returns the identifier of this Thread.
static Thread currentThread() Returns a reference to the currently executing thread object.
void checkAccess() Determines if the currently running thread has permission to modify this thread.
static void yield() A hint to the scheduler that the current thread is willing to yield its current use of a processor.


Class Thread

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.