I have been using Vertx for 3 month, but now I wonder how non blocking Vertx JDBC works,for example
private void selectEndedMatches(){
this.jdbcClient.getConnection(conn->{
if(conn.failed()){
log.error("Can't get Vertx connection",conn.cause());
} else{
final SQLConnection connection = conn.result();
connection.queryWithParams("select matchid from get5_stats_matches where matchid > ? and end_time is not null",new JsonArray().add(this.lastMatchId),this::endedMatches);
connection.close();
}
});
}
private void endedMatches(final AsyncResult<ResultSet> rs) {
if(rs.failed()){
log.error("Can't make select statement from JdbcVerticle",rs.cause());
} else{
final List<JsonArray> results = rs.result().getResults();
final List<Integer> endedMatches = new ArrayList<>(results.size());
for (final JsonArray result : results) {
endedMatches.add(result.getInteger(0));
}
}
}
Here we provide a callback that will be executed when our select statement will return a result from DB, but how it works.
I didn't find an answer in docs https://vertx.io/docs/vertx-jdbc-client/java/
In my opinion:
Vertx use one of the worker threads to do select statement to not block Event loop thread.But in this case each sql query need a separate thread to execute. But what if Vertx doesn't use any separate thread to execute query, in this case how event loop know when result came from DB, using threads it's pretty simple, Event loop can check current state of thread that is used by jdbc query, and if state is ready it's mean that Event loop should to execute Call back
Am i correct?