12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2007 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
165d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
175d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao/**
185d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao * Make sure that a sub-thread can join the main thread.
195d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao */
205d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaopublic class Main {
215d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public static void main(String[] args) {
225d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        Thread t;
235d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
245d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        t = new Thread(new JoinMainSub(Thread.currentThread()), "Joiner");
255d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        System.out.print("Starting thread '" + t.getName() + "'\n");
265d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        t.start();
275d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
285d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        try { Thread.sleep(1000); }
295d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        catch (InterruptedException ie) {}
305d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
315d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        System.out.print("JoinMain starter returning\n");
325d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
335d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
345d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
355d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhaoclass JoinMainSub implements Runnable {
365d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    private Thread mJoinMe;
375d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
385d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public JoinMainSub(Thread joinMe) {
395d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        mJoinMe = joinMe;
405d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
415d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
425d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    public void run() {
435d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        System.out.print("@ JoinMainSub running\n");
445d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao
455d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        try {
465d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            mJoinMe.join();
475d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.out.print("@ JoinMainSub successfully joined main\n");
485d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        } catch (InterruptedException ie) {
495d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.out.print("@ JoinMainSub interrupted!\n");
505d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        }
515d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        finally {
525d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao            System.out.print("@ JoinMainSub bailing\n");
535d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao        }
545d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao    }
555d1ac920fdaef5d4ec8f66bb734488cd9660b024jeffhao}
56