MyRunnable.java
public class MyRunnable implements Runnable
{
public void run()
{
Thread t = Thread.currentThread();
// tests if this thread is alive
System.out.println(t.getName()+" - isAlive = " + t.isAlive());
}
}
ThreadDemo.javapublic class ThreadDemo
{
public static void main(String args[]) throws InterruptedException
{
Thread t = new Thread(new MyRunnable());
// this will call run() function
t.start();
// waits for this thread to die
t.join();
// tests if this thread is alive
System.out.println(t.getName()+" - isAlive after join = " + t.isAlive());
}
}
OutputThread-0 - isAlive = true
Thread-0 - isAlive after join = false
Click the below link to download the code:
No comments:
Post a Comment