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 TypeMethod NameDescription
voidstart()Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
static voidsleep(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.
voidsetPriority(int newPriority)Changes the priority of this thread.
voidsetName(String name)Changes the name of this thread to be equal to the argument name.
voidsetDaemon(boolean on)Marks this thread as either a daemon thread or a user thread.
voidsetContextClassLoader(ClassLoader cl)Sets the context ClassLoader for this Thread.
voidrun()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.
voidjoin()Waits for this thread to die.
voidjoin(long millis)Waits at most millis milliseconds for this thread to die.
booleanisInterrupted()Tests whether this thread has been interrupted.
booleanisDaemon()Tests if this thread is a daemon thread.
booleanisAlive()Tests if this thread is alive.
static booleanholdsLock(Object obj)Returns true if and only if the current thread holds the monitor lock on the specified object.
Thread.StategetState()Returns the state of this thread.
StackTraceElement[]getStackTrace()Returns an array of stack trace elements representing the stack dump of this thread.
intgetPriority()Returns this thread’s priority.
StringgetName()Returns this thread’s name.
longgetId()Returns the identifier of this Thread.
static ThreadcurrentThread()Returns a reference to the currently executing thread object.
voidcheckAccess()Determines if the currently running thread has permission to modify this thread.
static voidyield()A hint to the scheduler that the current thread is willing to yield its current use of a processor.

References

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.