Java Thread.isAlive()
Syntax
Thread.isAlive() has the following syntax.
public final boolean isAlive()
Example
In the following code shows how to use Thread.isAlive() method.
//from w w w . j av a 2 s . co m
class ThreadDemo implements Runnable {
public void run() {
Thread t = Thread.currentThread();
// tests if this thread is alive
System.out.println("status = " + t.isAlive());
}
}
public class Main {
public static void main(String args[]) throws Exception {
Thread t = new Thread(new ThreadDemo());
// this will call run() function
t.start();
// waits for this thread to die
t.join();
// tests if this thread is alive
System.out.println("status = " + t.isAlive());
}
}