Câu hỏi phỏng vấn Spring
Câu hỏi

What are the Mon...

Câu trả lời

Mono and Flux are both reactive programming types from the Project Reactor library, which is used extensively in the Spring WebFlux framework to implement reactive applications.

Mono

Mono is a reactive stream that can emit at most one item. It represents a single or absent asynchronous value. Mono is similar to the CompletableFuture from Java 8 but is non-blocking and supports reactive streams backpressure. It is used when an operation can result in zero or one result. Mono can complete with either a value, an error, or no value (empty Mono). This makes it suitable for tasks like network calls or database queries where you expect a single result or none at all[1][2][5][12].

Flux

Flux, on the other hand, is a reactive stream that can emit zero or more items. It represents a stream of data that can be handled asynchronously and supports backpressure as well. Flux is used when an operation returns multiple items over time, such as processing streams of data from a database or responses from a network call. It can handle any number of elements, from zero to N, and like Mono, it can also complete with an error[3][4][8][13].

Both Mono and Flux implement the Publisher interface from the Reactive Streams specification, ensuring that they fit into the reactive programming model which is designed to handle stream processing in a non-blocking and backpressure-aware manner. This model is particularly useful in scenarios involving I/O-bound tasks, where traditional blocking operations can lead to inefficient re...

expert

expert

Gợi ý câu hỏi phỏng vấn

junior

What does a bean definition contain?

senior

Compare @Component (v2.5) versus @Bean (v 3.0)

junior

What is Spring Boot?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào