프로그래밍/JAVA

자바 Thread 순서 보장하기

kkwonsy 2020. 5. 26. 17:50

 

 

 

자바 Thread 순서 보장하기 -> Thread.join()

https://defacto-standard.tistory.com/1191 

 

public void main(String[] args) {
	Thread t1 = new Thread(new CThread(1));
    Thread t2 = new Thread(new CThread(2));
    Thread t3 = new Thread(new CThread(3));
    Thread t4 = new Thread(new CThread(4));
    Thread t5 = new Thread(new CThread(5));
    
    t1.start();
    t2.start();
    t3.start();
    t1.join();
    t2.join();
    t3.join();
    
    t4.start();
    t5.start();
    t4.join();
    t5.join();
}

public class CThread implements Runnable {
	@Override
    public void run () {
    	System.out.println(Thread.currentThread().getName() + " "); 
    }	
}

결과

 

 

 

Locking Reads