Multithreading with Apache DBCP Multithreading with Apache DBCP multithreading multithreading

Multithreading with Apache DBCP


A thread takes a connection from the pool and makes exclusive use of it until it is done, it doesn't share the connection with other threads. When it is done it returns the connection to the pool (usually the connection overrides the close method to return it to the pool). The benefit is that the connections don't have to be recreated for each use. But you shouldn't have multiple threads making simultaneous use of a database connection.


Yes, Apache DBCP can work in multi-threads simultaneously. "block" happens when client code getConnection() to ensure correct behavior under race condition, for example, one Connection instance should not be got by two concurrent getConnection() requests. After that client code handles the Connection instances.

Concurrent scenario is major concern at server side pooling, such as popular Apache DBCP. So I think DBCP does well behavior in multi-thread, although I don't dive into the library deep.

And Apache DBCP just provides JDBC connection pooling, client code must use the Connection instances in correct multi-threads way which DBCP cannot guarantee.