我的 Java Play2 应用程序正在调用一些外部 Web 服务以通过同步的 3rd 方客户端库获取数据。对于这个应用程序,我需要高流量和可扩展性。
Play 文档说:
Cases when your code may block include: Using REST/WebService APIs through a 3rd party client library (ie, not using Play’s asynchronous WS API) [...]
Note that you may be tempted to therefore wrap your blocking code in Futures. This does not make it non blocking, it just means the blocking will happen in a different thread[...]
In contrast, the following types of IO do not block: The Play WS API, ...
在 Play2 Java 应用程序中,使用 Promise 使事情异步化并不是很有用,因为默认的 Play 池用于 Futur 任务。因此,使用大量 Futur 将导致与仅使用具有大型默认线程池的同步调用相同的结果:同一池中的线程数量大致相同。
所以我的问题是:
非常感谢
洛伊克
最佳答案
正如 Guillaume Bort 在 Play 邮件列表中所说,play.libs.WS API“有自己的线程池,由 AsyncHttp 库本身管理,但由于它在幕后使用 NIO,所以它并不重要,因为它基本上是真的非阻塞。”
所以应该尽可能多地使用它。
关于playframework - Play 2 : play. libs.WS VS 3rd 方客户端库用于异步处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16504841/