简体   繁体   中英

Connection Pooling Scanario in Tomcat

I am trying to understand a specific scenario in database connection pooling. Any pointers on this will be very helpful.

Setup :

  1. Tomcat webserver
  2. MySQL Server (max connections = 18)

Configuration of webapp :
The context.xml of the webapp has these parameters for the database connection pool :

<Context path=...
   <Resource name=... maxActive="20" maxIdle="18" 
    removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
    validationQuery="select 1" testOnBorrow="true"... />
</Context>

Scenario :
The webapp opens and closes a lot of connections. However, the pool holds on to 18 of them (as maxIdle=18) when the webapp is not transacting any more with the dB.
Now at this point of time, a separate Pure Java standalone application requests for a database connection. How will the MySQL server respond?

  1. Will it provide a connection by closing an idle connection being held by the pool?
  2. Will it refuse a connection as maximum number of dB connections are already open (being held by the pool)

If I am not clear with the scenario, please let me know, and I will clarify further.

Cheers, Rohitesh

DB server does not know if an open connection is from pool or not. For DB server it's just an open connection and it will never close it on its own initiative.

The connection limit of your pool has nothing to do with the total connection limit of your database. It is just the limit of that specific connection pool. Other applications will be able to allocate connections as long as the total limit configured for your server hasn't been reached.

Of course having connection pools keeping a lot of (idle) connections open will mean that you reach a configured server limit (default is 100 for MySQL) faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM