2024/07/06
-
Java21 Virtual Thread프로그래밍/Java 2024. 7. 6. 16:55
1. Java 21에서 가상 스레드를 왜 도입하였을까. 1) IO 중심 작업에서 처리량(성능)을 늘리기 위함- 대표적인 IO 중심 작업은 DB를 사용하는 웹 서버를 예로 들수 있다. - DB를 사용하는 웹 서버는 DB와 통신하기 위해 IO를 사용한다.- 즉, IO 중심이 많은 서버에서 처리량을 늘리기 위해 나온 것이 가상 스레드다. 2) 트래픽이 많음 + IO가 많이 발생함 + 요청마다 쓰레드를 만드는 방식- 이 방식을 사용하게되면 스레드가 메모리를 사용하기 때문에 많은 메모리가 사용된다.- IO가 발생하면 응답 대기 (blocking) 되는 시간, 컨텍스트 스위칭에 따른 CPU 낭비가 발생함.- 위와 같은 문제 때문에 스레드를 늘리고 싶어도 늘리지 못한다. 그리고 서버들은 스레드를 pool로 관리한다..