Issue
I'm new at Spring and I'm reading one book "Pro Spring boot 2". It says here that Spring Web MVC has some blocking on each request, and Spring Webflux is a completely non-blocking stack.
- Tell me, please, what is meant?
- The request that came to Spring MVC activates one thread to execute this request. When and why is it blocked?
- And why doesn't Spring WebFlux block thread?
Solution
- Spring Web MVC takes a single thread to handle each request to your API. Spring Webflux does not block a thread to handle each request, because no thread is kept waiting for something to be done (e.g. waiting for an answer from a database).
- As written in 1., it can be blocked while waiting for an answer from a database or from another service that is called via HTTP.
- Spring Webflux takes advantage of the reactive stack (take a look at https://projectreactor.io/) which is fully non-blocking. This means that no thread is blocked waiting for something to happen. Everything is based on reactive streams publishers (Mono and Flux) making your code reactive to data being available (from a database or from another service called via HTTP as examples).
Answered By - João Dias
Answer Checked By - David Marino (JavaFixing Volunteer)