Searching...
Thursday, 7 November 2013

How to get Java Thread State

09:01

Release 5.0 introduced the Thread.getState() method. When called on a thread, one of the following Thread.State values is returned:
NEW
RUNNABLE
BLOCKED
WAITING
TIMED_WAITING
TERMINATED

Example

package com.pretech;
public class ThreadState {
	public static void main(String[] args) {
		Threadone t1 = new Threadone();
		System.out.println(t1.getState());
		t1.start();
		System.out.println(t1.getState());
	}
}
class Threadone extends Thread {
	public void run() {
		System.out.println("HelloWorld");
	}
}

Output



NEW
RUNNABLE
HelloWorld
TERMINATED


0 comments: