blocking에 해당하는 글 1

  1. reactor Schedulers2019.12.16

reactor Schedulers

JAVA/Spring|2019. 12. 16. 20:47

Mono 혹은 Flux를 다룰때 map 혹은 subscribe 동작들을
subscribeOn()이나 publishOn()을 통해 다른 스레드에서 실행될 수 있도록 위임할수 있는데
인자는 Scheduler를 받습니다.


Spring WebFlux에서 Controller 스레드에서는 blocking 작업을 할수 없도록 되어있기에
필요한 경우에 subscribeOn() 를 사용하여 blocking 작업을 다른 스레드에서 사용할 수 있는데
Scheduler 종류마다 blocking 작업이 가능한 Scheduler가 있고 아닌 Scheduler 가 있습니다.
(non-blocking 스케줄은 블럭킹 작업이 불가능합니다.)





새로 신규로 생성하여 넘길수 있겠지만 Schedulers가 기본적으로 몇가지를 지원합니다.

  • parrallel
    • optimized for fast non-blocking executions
    • 속도 최적, non-blocking
  • single
    • optimized for low-latency one-off executions
    • 스레드 하나를 공유함, non-blocking
  • elastic
    • optimized for longer executions, alternative for blocking tasks where the number of active tasks can grow indefinitely
    • 긴작업에 최적, non-blocking 아님, blocking 작업 가능 스레드, 필요시 무한히 늘어남
  • boundedElastic
    • optimized for longer executions, alternative for blocking tasks where the number of active tasks is capped
    • 긴작업에 최적, non-blocking 아님, blocking 작업 가능 스레드, 정해진 사이즈
  • immediate
    • to run a task on the caller Thread
    • 콜러 스레드에서 실행
  • fromExecutorService
    • 기존 java.util.concurrent.Executors 를 활용

댓글()