public class ThreadTest extends Thread{
	private int j = 1;
	public ThreadTest(String name){
		setName(name);
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		//super.run();
		for(int i=1;i<1000000;i++){
			j++;
		}
		System.out.println("线程"+Thread.currentThread().getName()+"执行完毕"+j);
	}
	
	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(new ThreadTest("T1")); 
		Thread t2 = new Thread(new ThreadTest("T2")); 
		Thread t3 = new Thread(new ThreadTest("T3"));

		t1.start(); 
		t1.join();

		t2.start(); 
		t2.join();

		t3.start(); 
		t3.join();
	}

}

主要使用的join方法实现,直到当前线程执行完才会唤醒其他线程继续执行

现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?使用join

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-07-12
  • 2021-04-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-12-07
  • 2021-08-05
  • 2022-02-09
相关资源
相似解决方案