It seems that there is a problem while closing the jdbc client.
My application requires me to create a new jdbc client on each request and close it after the request is done (request involves CRUD operations). But, as the requests go on increasing, the service stops to take any requests ( saying 'Too many files open') and it seems that jdbc client is not properly closed.
public static void query(String sql, JsonObject databaseConfig, Handler<AsyncResult<JsonObject>> done) {
JDBCClient client = JDBCClient.createShared(Holder.getInstance().getVertx(), databaseConfig);
client.getConnection(connect -> {
if (connect.failed())
done.handle(Future.failedFuture(connect.cause()));
SQLConnection connection = connect.result();
connection.query(sql, result -> {
if (result.failed())
done.handle(Future.failedFuture(result.cause()));
else
done.handle(Future.succeededFuture(result.result().toJson()));
connection.close(kil -> {
if (kil.failed()) {
throw new RuntimeException(kil.cause());
}
});
client.close();
});
});
}
I'm closing the client after connection is closed.
Is this the right way to close the client? cause I'm having problem with it everytime.
Please suggest. Thanks!