Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /**
     18  * Make sure that a sub-thread can join the main thread.
     19  */
     20 public class Main {
     21     public static void main(String[] args) {
     22         Thread t;
     23 
     24         t = new Thread(new JoinMainSub(Thread.currentThread()), "Joiner");
     25         System.out.print("Starting thread '" + t.getName() + "'\n");
     26         t.start();
     27 
     28         try { Thread.sleep(1000); }
     29         catch (InterruptedException ie) {}
     30 
     31         System.out.print("JoinMain starter returning\n");
     32     }
     33 }
     34 
     35 class JoinMainSub implements Runnable {
     36     private Thread mJoinMe;
     37 
     38     public JoinMainSub(Thread joinMe) {
     39         mJoinMe = joinMe;
     40     }
     41 
     42     public void run() {
     43         System.out.print("@ JoinMainSub running\n");
     44 
     45         try {
     46             mJoinMe.join();
     47             System.out.print("@ JoinMainSub successfully joined main\n");
     48         } catch (InterruptedException ie) {
     49             System.out.print("@ JoinMainSub interrupted!\n");
     50         }
     51         finally {
     52             System.out.print("@ JoinMainSub bailing\n");
     53         }
     54     }
     55 }
     56