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
No comments:
Post a Comment