Thread.getState() has the following syntax.
public Thread.State getState()
In the following code shows how to use Thread.getState() method.
class ThreadDemo implements Runnable { /*from www. jav a2s .c o m*/ public void run() { // returns the state of this thread Thread.State state = Thread.currentThread().getState(); System.out.println(Thread.currentThread().getName()); System.out.println("state = " + state); } } public class Main{ public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); // this will call run() function t.start(); } }
The code above generates the following result.