본문 바로가기

프로그래밍/JAVA

자바 Thread 순서 보장하기

 

 

 

자바 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

'프로그래밍 > JAVA' 카테고리의 다른 글

디자인 패턴 몇가지 정리  (0) 2020.06.03
Java trouble shooting  (0) 2020.04.03
Thread Dump & Heap Dump  (0) 2019.08.31
자바8 Optional  (0) 2019.04.23
WebFlux & Non-blocking  (0) 2019.04.22