Spring 异步与 Websocket 的优点/缺点
Advantages / Drawbacks of Spring Async vs. Websocket
使用 Spring @Async 和 Spring Websockets 进行数据库查询等长时间后台任务的主要区别、优点和缺点是什么?两者是否同等使用,或者是否存在其中一种更适合的特殊情况?
相对不频繁的长后台任务是 @Async
的情况。 Websocket 更适合客户端和服务器之间的密集通信,例如聊天客户端。
来自 Spring 文档:
The best fit for WebSocket is in web applications where the client and
server need to exchange events at high frequency and with low latency.
Prime candidates include, but are not limited to, applications in
finance, games, collaboration, and others. Such applications are both
very sensitive to time delays and also need to exchange a wide variety
of messages at a high frequency.
For other application types, however, this may not be the case. For example, a news or social feed that shows breaking news as it
becomes available may be perfectly okay with simple polling once every
few minutes. Here latency is important, but it is acceptable if the
news takes a few minutes to appear.
Even in cases where latency is crucial, if the volume of messages is relatively low (e.g. monitoring network failures) the use of long
polling should be considered as a relatively simple alternative that
works reliably and is comparable in terms of efficiency (again
assuming the volume of messages is relatively low).
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
使用 Spring @Async 和 Spring Websockets 进行数据库查询等长时间后台任务的主要区别、优点和缺点是什么?两者是否同等使用,或者是否存在其中一种更适合的特殊情况?
相对不频繁的长后台任务是 @Async
的情况。 Websocket 更适合客户端和服务器之间的密集通信,例如聊天客户端。
来自 Spring 文档:
The best fit for WebSocket is in web applications where the client and server need to exchange events at high frequency and with low latency. Prime candidates include, but are not limited to, applications in finance, games, collaboration, and others. Such applications are both very sensitive to time delays and also need to exchange a wide variety of messages at a high frequency.
For other application types, however, this may not be the case. For example, a news or social feed that shows breaking news as it becomes available may be perfectly okay with simple polling once every few minutes. Here latency is important, but it is acceptable if the news takes a few minutes to appear.
Even in cases where latency is crucial, if the volume of messages is relatively low (e.g. monitoring network failures) the use of long polling should be considered as a relatively simple alternative that works reliably and is comparable in terms of efficiency (again assuming the volume of messages is relatively low).
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html