Is OracleDataSource.getConnection thread safe?

I thought it would be easy to find this answer ... but not much.

Does anyone know if the OracleDataSource.getConnection method is thread safe?

I don't mean the Connection objects it returns, but it calls getConnection itself.

Specifically this method: ()

The docs and class don't say it explicitly, but being like a connection pool, I tend to believe it is.


source to share

1 answer

This is a problem discussed in Java Concurrency in Practice (Brian Goetz):

4.5.1. Interpreting undefined documentation

Many Java technology specifications are silent, or at least do not regret the thread safety guarantees and requirements for interfaces such as ServletContext, HttpSession, or DataSource.

... information about servlets ...

You can draw a similar conclusion about the JDBCDataSource interface, which is a pool of connections to reusable databases. The DataSource provides a service to the application and it doesn't make much sense in the context of a single threaded application. It's hard to imagine a use case that doesn't involve calling getConnection from multiple threads. And, as with servlets, the examples in the JDBC specification do not indicate the need for client-side locking in many of the code examples using DataSource. So while the spec does not promise that the DataSource is thread safe, or requires container producers to provide a thread safe implementation, the same "would be absurd if it weren't an argument, we have no choice but to assume that DataSource.getConnection does not require additional client side locking ....



All Articles