My Java Play2 app is calling some external web services to get data through a synchronous 3rd party client library. For this app I need high traffic and scalability.
The play documentation says :
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, ...
In a Play2 Java app, it's not really useful to use promises to make things asynchronous because the default play pool is used for Futur tasks. As a result, using a lot of Futur will result as the same thing as using only synchronous calls with a large default thread pool : roughly same number of threads in the same pool.
So my questions are :
Thanks a lot
Loïc
As Guillaume Bort said on the Play mailing list, play.libs.WS API "has its own thread-pool, managed by the AsyncHttp library itself, but since it uses NIO under the hood, it doesn't matter as it is basically really non-blocking."
So it should be used as often as possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With