官术网_书友最值得收藏!

Asynchronous HTTP with Spring Web MVC

The introduced in Servlet 3.0 asynchronous support expands the ability to process an HTTP request in non-container threads. Such a feature is pretty useful for long-running tasks. With those changes, in Spring Web MVC we can return not only a value of type T in @Controller but also a Callable<T> or a DeferredResult<T>. The Callable<T> may be run inside a non-container thread, but still, it would be a blocking call. In contrast, DeferredResult<T> allows an asynchronous response generation on a non-container thread by calling the setResult(T result) method so it could be used within the event-loop.

Starting from version 4.2, Spring Web MVC makes it possible to return ResponseBodyEmitter, which behaves similarly to DeferredResult, but can be used to send multiple objects, where each object is written separately with an instance of a message converter (defined by the HttpMessageConverter interface).

The SseEmitter extends ResponseBodyEmitter and makes it possible to send many outgoing messages for one incoming request in accordance with SSE's protocol requirements. Alongside ResponseBodyEmitter and SseEmitter, Spring Web MVC also respects the StreamingResponseBody interface. When returned from @Controller, it allows us to send raw data (payload bytes) asynchronously. StreamingResponseBody may be very handy for streaming large files without blocking Servlet threads.

主站蜘蛛池模板: 南丹县| 大化| 辽阳县| 镇赉县| 体育| 祁阳县| 枞阳县| 历史| 保靖县| 辽中县| 兴义市| 肥东县| 江达县| 白山市| 佛山市| 罗定市| 博乐市| 武城县| 汉中市| 泰安市| 行唐县| 通辽市| 靖江市| 炉霍县| 辉南县| 荣成市| 郓城县| 博兴县| 婺源县| 广饶县| 明星| 昌黎县| 怀安县| 磐石市| 南城县| 兴城市| 江阴市| 休宁县| 尚义县| 航空| 扶风县|