java - OracleDataSource.getConnection 是线程安全的吗?

标签 java oracle thread-safety

我认为找到这个答案会很容易......但不是那么容易。

有人知道 OracleDataSource.getConnection 方法是否线程安全吗?

我指的不是它返回的Connection对象,而是getConnection本身的调用。

具体来说,这个方法:http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/jdbc/pool/OracleDataSource.html#getConnection()

文档和类没有明确说明,但是,作为一个连接池,我倾向于相信它是。

最佳答案

这是 Java Concurrency in Practice (Brian Goetz) 中讨论的问题:

4.5.1。解释模糊文档

Many Java technology specifications are silent, or at least unforthcoming, about thread safety guarantees and requirements for interfaces such as ServletContext, HttpSession, or DataSource.

...关于 servlet 的信息...

One can make a similar inference about the JDBCDataSource interface, which represents a pool of reusable database connections. A DataSource provides service to an application, and it doesn't make much sense in the context of a single threaded application. It is 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 suggest the need for any client side locking in the many code examples using DataSource. So, even though the specification doesn't promise that DataSource is thread-safe or require container vendors to provide a thread-safe implementation, by the same "it would be absurd if it weren't" argument, we have no choice but to assume that DataSource.getConnection does not require additional client-side locking. ...

关于java - OracleDataSource.getConnection 是线程安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26345436/

相关文章:

java - 为什么我的数组打印全零而不是范围内的所有整数?

java - SpringApplicationConfiguration 无法解析为类型

oracle - 在 PL/SQL Developer 中直接从一个包体跳转到另一个包体

java - 按钮不会打开新 Activity

Java用未知索引替换arraylist中的对象

sql - 减少 Oracle 数据库中 SQL 函数中的字符数

java.sql.SQLException : Invalid column name 异常

android - Activity 类型中的方法 runOnUiThread(Runnable) 不适用于参数 (void)

java - 如何暂停其他正在进行的流读取器线程

java - 如何从非 ui 线程(从表面 View 绘制线程)启动 Activity