본문 바로가기

전체 글

(7)
[Java 21] Virtual Thread 의 원리 - Continuation 들어가며Java 21 에는 경량 스레드 모델인 Virtual Thread 가 추가되었습니다. 기존 Java 의 스레드는 커널의 스레드와 1 대 1 매칭이 되기 때문에, 다수의 스레드를 사용하여 프로그래밍 하기에는 컨텍스트 스위칭 비용이 많이 들었습니다. 이를 보완하기 위해 Spring Webflux 와 같은 Reactive Programing 이나 Kotlin 의 Coroutine 을 많은 곳에서 적용하고 있으며, Spring Webflux + Kotlin Coroutine 조합은 하나의 표준처럼 보여지기도 합니다. 하지만, Webflux 를 사용하기 위해서는 DB 등의 드라이버들이 Mono, Flux 를 사용하는 Reactive 방식을 지원해주어야 하며, 잘못하여 blocking 로직이 애플리케이션에 ..
Spring Webflux filter 로직 살펴보기 Problemspring webflux 에서 logging, exception handling 을 위해서 filter 로직을 넣고자 했습니다. 로깅은 분석을 위해서 request body 와 response body 를 같이 기록하고자 하였고, exception 같은 경우 exception filter 에서 잡아 약속된 error 응답 형식으로 내려주고자 하였습니다. 또한 exception filter 가 먼저 수행되도록 하여 exception 이 발생한 request 도 기록할 수 있도록 filter 의 순서도 고려 대상이었습니다. webflux 에는 controller annotation 방식, router 방식 두가지가 있으며, webfilter, handlerFilterFunction 등 두 방식..
spring webflux, kotlin coroutine 환경에서 aop 사용해보기 Background) Spring reactive cacheThis topic is still relatively new. At the time of writing this article, there was no fluent integration between @Cacheable and reactive frameworks. The primary issue is that there are no non-blocking cache implementations (JSR-107 cache API is blocking). Only Redis is providing a reactive driver.Despite the issue we mentioned in the previous paragraph, we can st..