TestJoin.java 620 B

123456789101112131415161718192021222324252627282930313233
  1. public class TestJoin {
  2. public static void main(String[] args) {
  3. TestJoinA a = new TestJoinA();
  4. TestJoinB b = new TestJoinB(a);
  5. b.start();
  6. a.start();
  7. }
  8. }
  9. class TestJoinA extends Thread {
  10. @Override
  11. public void run() {
  12. System.out.println("A");
  13. }
  14. }
  15. class TestJoinB extends Thread {
  16. private TestJoinA a;
  17. public TestJoinB(TestJoinA a) {
  18. this.a = a;
  19. }
  20. @Override
  21. public void run() {
  22. try {
  23. a.join();
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. System.out.println("B");
  28. }
  29. }