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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JDBC
Connectionis by definition single-threaded. When one thread obtains connection fromDataSource(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
DataSourcefor 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.