1 // Test the status of the isAlive() flag before, during, and after thread 2 // execution. Check that thread's threadgroup is null after thread exits. 3 4 public class Thread_Alive implements Runnable 5 { main(String args[])6 public static void main(String args[]) throws InterruptedException 7 { 8 Thread_Alive ta = new Thread_Alive(); 9 Thread t = new Thread(ta); 10 System.out.println(t.isAlive()); 11 t.start(); 12 System.out.println(t.isAlive()); 13 14 Thread.sleep(50); 15 16 synchronized (ta) 17 { 18 ta.notifyAll(); 19 } 20 21 t.join(); 22 System.out.println(t.isAlive()); 23 24 try 25 { 26 t.start(); 27 System.out.println("Error: dead thread can be restarted."); 28 } 29 catch (IllegalThreadStateException x) 30 { 31 System.out.println ("ok"); 32 } 33 34 System.out.println(t.getThreadGroup()); 35 } 36 run()37 public synchronized void run() 38 { 39 try 40 { 41 wait(); 42 } 43 catch (InterruptedException x) {} 44 } 45 46 } 47