Java join线程源代码全面透析


  本文标签:Java join线程

Java join线程在使用的时候需要我们不断的学习相关编程的知识  。下面我们就先来看看有关Java join线程的源代码  。只有这样才能更好的进行相关问题的解决,希望大家有所收获  。

使调用join()的线程执行完毕后才能执行其它线程,在一定意义上,它可以实现同步的功能  。

  1. class TestThreadMethod extends Thread{  
  2. public static int shareVar = 0;  
  3. public TestThreadMethod(String name){  
  4. super(name);  
  5. }  
  6. public void run(){  
  7. for(int i=0; i<4; i++){  
  8. System.out.println(" " + i);  
  9. try{  
  10. Thread.sleep(3000);  
  11. }  
  12. catch(InterruptedException e){  
  13. System.out.println("Interrupted");  
  14. }  
  15. }  
  16. }  
  17. }  
  18. public class TestThread{  
  19. public static void main(String[] args){  
  20. TestThreadMethod t1 = new TestThreadMethod("t1");  
  21. t1.start();  
  22. try{  
  23. t1.join();  
  24. }  
  25. catch(InterruptedException e){}  
  26. t1.start();  
  27. }  

以上就是对Java join线程源代码的相关介绍  。