I am brand new to Akka (Java lib) and am trying to understand if Akka can be used to make non-blocking requests to JDBC, and if so, what that it would look like. I believe most JDBC drivers open a socket connection and block the thread that created it until a particular JDBC response is received, and so there might not be much Akka can do to help here, but I am wondering if there is a way (perhaps through Futures or Agents?) that Akka could help improve performance, and allow the actor system to continue processing data, while an existing JDBC call is being made and awaiting a response.
I found this article which is a bit vague/cryptic, but it sounds like futures might be the key here. However that article doesn’t really show any meaningful (real-world) code examples, and so I’m still at a loss. So let’s say we have a stored procedure, sp_make_expensive_calculation
, that normally takes 10 - 30 seconds to return a response and that is normally called via JDBC like so:
String makeExpensiveCalculationSql = "{call sp_make_expensive_calculation(?)}";
callableStatement = dbConnection.prepareCall(makeExpensiveCalculationSql);
callableStatement.setInt(1, 10);
// Could take up to 30 seconds to complete.
callableStatement.executeUpdate();
int answer = callableStatement.getString(2);
Can Akka do anything to help here so that the actor system can continue processing data (and even make other sp_make_expensive_calculation
calls) while we wait for the first call to return?