Play 2 allows you to do async webservice calls through AsyncResult which won't block the thread:
public static Result feedTitle(String feedUrl) {
return async(
WS.url(feedUrl).get().map(
new Function<WS.Response, Result>() {
public Result apply(WS.Response response) {
return ok("Feed title:" + response.asJson().findPath("title"));
}
}
)
);
}
This only works if you're doing simple things like passing the result of the WS call straight through to the user. However, what if you have to do additional operations on the result?
Looking at the documentation, it seems like you can do this:
Promise<Response> promise = WS.url("http://some.website.com").get();
Response response = promise.get(); // I've got the result, but I've also blocked
Which obviously is not ideal. Is there a way of doing async calls while allowing Play to pass execution to other threads?