I\'ve written a function in Java that runs a MySQL query and returns results. I\'ve implemented connection pooling using this method here: http://www.kodejava.org/how-do-i-creat
You create a connection pool, but you don't put anything into it. You connection pool is empty when it is created, so your first request to it is guaranteed to to create a new connection and will be just as slow as getting a connection manually.
Try putting your code into a loop, where you repeatedly get a connection from the pool. Try it once, five times, ten times and fifteen times. Note how the results change.
Some connection pools support automatically creating and holding a minimum number of connections ready for use as well as a maximum. When the pool is initialised it will pre-fetch connections so the first few calls aren't delayed.
You will not see a difference with a single request to the DB. You have to test this this with multiple (concurrent) requests.
And BTW: You you obeye the Java naming convention and start all objects with lower case.
Your use case does not warrant a connection pool. Its just one connection you need.
The pool class you are using GenericObjectPool
has a method addObject();. This will create and add the objects to the pool. This will avoid creating connection later.
Your can pre-load your pool by calling connectionPool.addObject()
. At the start it is empty and creates a connection only after you've posted a query.