Thread default methods

thread.sleep()
Both within threads and within the main method, a call to Thread.sleep is used to pause the program. sleep is a static method of the Thread class that can be called with one or two parameters.

thread.isAlive()
This method can be used to determine whether the current thread is still running.

thread.join()
The join method waits for the end of the thread for which it was called. It thus makes it possible to start a process and wait with further execution until the process has ended.

thread.checkAccess():
Determines if the currently running thread has permission to modify this thread.

thread.getPriority()
Returns this thread’s priority.

thread.getState()
Returns the state of this thread. This method is designed for use in monitoring of the system state, not for synchronization control.

thread.getName()
Returns this thread’s name.

thread.getClass(), thread.clone(), thread.hashCode(), thread.isInterrupted(), thread.wait() and much more…

Example

public class MyThread extends Thread {
	public void run() {
		System.out.println("Thread is running");
	}

	public static void main(String[] args) {
		MyThread thread = new MyThread();
		thread.start();

		System.out.println(thread.getName());
		System.out.println(thread.isAlive());
		System.out.println(thread.getState());
		System.out.println(thread.getPriority());
	}
}
Output first run
Thread-0
Thread is running
false
TERMINATED
5
Output second run
Thread-0
true
BLOCKED
5
BLOCKED
Thread is running