Java MySQL connetion pool is not working

后端 未结 4 1019
猫巷女王i
猫巷女王i 2021-01-26 03:46

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

4条回答
  •  甜味超标
    2021-01-26 04:08

    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.

提交回复
热议问题