As per my understanding, database connection pool usually works this way:
- create n connections during app initialization and put them into a cache(e.g. a list)
- a thread will require a connection to do some operation to the db and return the connection back when it has finished
- when there is no available connection in the cache, the thread in step2 will be waiting util a connection is pushed back to the cache
My question is:
Can we execute multiple db operations through one connection after we acquire it from the pool instead of do one db operation then put it back? it's seems more efficient, because it saves the time acquiring and putting back the connection. (under multiple threads condition, there must be some cost of locking when add
and get
from the connection pool)
can anyone help? Thks!