What will do a isAlive() method under Thread class?
What will do a isAlive() method under Thread class?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
The isAlive() method of thread class tests if the thread is alive. A thread is considered alive when the start() method of thread class has been called and the thread is not yet dead.
This method returns true if the thread is still running and not finished.
Basic Example:
public class CodeIsAlive extends Thread
{
public void run()
{
try
{
Thread.sleep(500);
System.out.println("Is run() method isAlive "+Thread.currentThread().isAlive());
}
catch (InterruptedException ie) {
}
}
public static void main(String[] args)
{
CodeIsAlive t1 = new CodeIsAlive();
System.out.println("Before starting thread isAlive: "+t1.isAlive());
t1.start();
System.out.println("After starting thread isAlive: "+t1.isAlive());
}
}