Domanda

Please help me understand hot the DBCP will work when multiple threads will try to use same connection?

A new connection will be spawned for every thread? And in this case there will be no advantage to use connection pool.

È stato utile?

Soluzione

JDBC Connection is by definition single-threaded. When one thread obtains connection from DataSource (DBCP or any other implementation), no other thread can touch that connection until it is released (closed, which actually puts the connection back into the pool).

DBCP won't prevent using the same connection from multiple threads. But if multiple threads ask DataSource for new connection at the same time, it will create as many connections as needed. If the number of concurrent threads exceeds max configured connections allowed to be spawned, getConnection() will block or fail.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top