I have a webservice that instantiates a single QueryRunner with a data source on initialization. It uses this one QueryRunner
object for all servlet requests from multiple different servlets used by the webapp by passing it around as a servlet context attribute. I.e.:
// in servlet context listener (on app initialization)
QueryRunner myQueryRunner = new QueryRunner(myDataSource);
myServletContext.setAttribute("queryRunner", myQueryRunner);
// in the servlets
QueryRunner myQueryRunner = (QueryRunner) myServletContext.getAttribute("queryRunner");
myQueryRunner.query(myStoredProcedure, handler, params)
I am trying to figure out if that is a bottleneck. Should the servlets be instantiating a new QueryRunner
with every request instead?
When looking around for an answer I also found this AsyncQueryRunner. But I just got more confused because the explanations in the API docs for QueryRunner and AsyncQueryRunner say the exact same thing.
I looked through the examples here and it seems that it should be instantiated with every request but I am not sure if that is just because it is example code.
In other words, when using DBUtils QueryRunner
should I:
- Use a single
QueryRunner
instance for every request? (what I am doing now) - Instantiate a new
QueryRunner
with every servlet request? - Use a single
AsyncQueryRunner
instance for every request?