1 // Copyright 2007 The Android Open Source Project 2 3 /** 4 * Make sure that a sub-thread can join the main thread. 5 */ 6 public class Main { main(String[] args)7 public static void main(String[] args) { 8 Thread t; 9 10 t = new Thread(new JoinMainSub(Thread.currentThread()), "Joiner"); 11 System.out.print("Starting thread '" + t.getName() + "'\n"); 12 t.start(); 13 14 try { Thread.sleep(1000); } 15 catch (InterruptedException ie) {} 16 17 System.out.print("JoinMain starter returning\n"); 18 } 19 } 20 21 class JoinMainSub implements Runnable { 22 private Thread mJoinMe; 23 JoinMainSub(Thread joinMe)24 public JoinMainSub(Thread joinMe) { 25 mJoinMe = joinMe; 26 } 27 run()28 public void run() { 29 System.out.print("@ JoinMainSub running\n"); 30 31 try { 32 mJoinMe.join(); 33 System.out.print("@ JoinMainSub successfully joined main\n"); 34 } catch (InterruptedException ie) { 35 System.out.print("@ JoinMainSub interrupted!\n"); 36 } 37 finally { 38 System.out.print("@ JoinMainSub bailing\n"); 39 } 40 } 41 } 42 43