Java program to check thread is alive or not
// Java program to check thread is
// alive or not
class MyThread implements Runnable {
public void run() {
try {
System.out.println("Thread is running.");
} catch (Exception e) {
}
}
}
public class Main {
public static void main(String[] args) {
Thread t = new Thread(new MyThread());
System.out.println("Thread isAlive: " + t.isAlive());
t.start();
System.out.println("Thread isAlive: " + t.isAlive());
}
}
Output
Thread isAlive: false
Thread is running.
Thread isAlive: true