- Hands-On Reactive Programming in Spring 5
- Oleh Dokuka Igor Lozynskyi
- 229字
- 2021-07-23 16:36:20
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.
- 物聯(lián)網(wǎng)標(biāo)準(zhǔn)化指南
- 網(wǎng)管員典藏書架:網(wǎng)絡(luò)管理與運維實戰(zhàn)寶典
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- Oracle SOA Suite 11g Performance Tuning Cookbook
- 農(nóng)產(chǎn)品物聯(lián)網(wǎng)研究與應(yīng)用
- 物聯(lián)網(wǎng)關(guān)鍵技術(shù)及應(yīng)用
- 互聯(lián)網(wǎng)基礎(chǔ)資源技術(shù)與應(yīng)用發(fā)展態(tài)勢(2021—2023)
- 無人機通信
- 物聯(lián)網(wǎng)通信技術(shù)
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- jQuery Mobile Web Development Essentials
- React Cookbook
- TCP/IP基礎(chǔ)(第2版)
- 精通SEO:100%網(wǎng)站流量提升密碼
- 計算機通信網(wǎng)絡(luò)安全