public class AppForConcurrentTest {
public static void main(String[] args) throws InterruptedException {
// InterruptedException 테스트
Thread testThread = new Thread(() -> {
try {
Thread.sleep(3000L);
System.out.println("Thread : " + Thread.currentThread().getName());
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
});
testThread.start();
System.out.println("Hello : " + Thread.currentThread().getName());
// main thread 가 testThread를 기다린다.
testThread.join();
System.out.println(Thread.currentThread().getName() + " is finished ");
// 출력
// Hello : main
// (3초 후)
// Thread : Thread-0
// main is finished
// "main is finished"는 main thread에 의해 "Thread : Thread-0" 이전에 나와야한다.
// 하지만 join 메서드로 인해 main thread는 testThread를 기다리게 된다.
}
}
Thread
Coucurrent 소프트웨어
자바에서 지원하는 Concurrent 프로그래밍
프로세스와 스레드의 차이
[OS] 프로세스와 스레드의 차이 - Heee's Development Blog
Step by step goes a long way.
gmlwjd9405.github.io
프로세스?
스레드?
자바 스레드 (Java Thread) ?
자바 멀티 쓰레드 프로그래밍
Thread 주요 기능
InterruptedException 테스트
Thread.join()
참고
Lesson: Concurrency (The Java™ Tutorials > Essential Classes) (oracle.com)
Thread (Java Platform SE 8 ) (oracle.com)
더 자바, Java 8 - 인프런
자바 8에 추가된 기능들은 자바가 제공하는 API는 물론이고 스프링 같은 제 3의 라이브러리 및 프레임워크에서도 널리 사용되고 있습니다. 이 시대의 자바 개발자라면 반드시 알아야 합니다. 이
www.inflearn.com
'기록 > JAVA' 카테고리의 다른 글