Java多线程____线程状态Join()方法
代码:
package com.test.thread;
public class TestRunnable implements Runnable{
	@Override
	public void run() {
		synchronized (this) {
			for (int i = 0; i < 10; i++) {
				System.out.println(Thread.currentThread().getName());
			}
		}
	}
	
}
package com.test.thread;
public class TestMain {
	
	public static void main(String[] args) {
		
		TestRunnable runnable_01=new TestRunnable();
		Thread thread1=new Thread(runnable_01, "runnable_01");
		TestRunnable runnable_02=new TestRunnable();
		Thread thread2=new Thread(runnable_02, "runnable_02");
		
			thread1.start();
					try {
						thread1.join();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
			thread2.start();
	}
	
}
运行结果
意思就是说某个子线程调用join方法时 其他线程要 等待他执行完 在执行
 
 
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号