AFAIK, if you look at the “computer-database” pattern, you are absolutely right, it blocks the main thread, since actions are not performed asynchronously.
Here is an excerpt from the sample :
public static Result list(int page, String sortBy, String order, String filter) { return ok( list.render( Computer.page(page, 10, sortBy, order, filter), sortBy, order, filter ) ); }
Here Computer.page() makes some blocking JDBC calls.
If you want to do this asynchronously, you must enclose the database call in an async(F.Promise<Result>) call async(F.Promise<Result>) . Something like that:
public static Result list(int page, String sortBy, String order, String filter) { return async( Akka.future( new Callable<Result>() { public Result call() { return ok( list.render( Computer.page(page, 10, sortBy, order, filter), sortBy, order, filter ) ); } } ) );
}
source share