OracleDataSource.getConnection是线程安全的吗? [英] Is OracleDataSource.getConnection thread-safe?

查看:283
本文介绍了OracleDataSource.getConnection是线程安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I thought finding this answer would be easy...but not so much.

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

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

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

I do not mean the Connection objects it returns, but the calling of getConnection itself.

具体来说,此方法:文档和类未明确说明,但作为连接池的方式,我倾向于相信它.

The docs and class doesn't say explicitly but, being as how its a connection pool, I'm inclined to believe it is.

推荐答案

这是 Java并发实践(Brian Goetz)

4.5.1.解释模糊的文档

许多Java技术规范对线程安全性保证和对诸如ServletContext,HttpSession或DataSource之类的接口的要求保持沉默,或者至少是不为人所知.

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的信息...

...information about servlets...

可以对JDBCDataSource接口做出类似的推断,该接口表示可重用的数据库连接池.数据源为应用程序提供服务,而在 单线程应用程序.很难想象一个不涉及从多个线程调用getConnection的用例.而且,与servlet一样,JDBC规范中的示例并不建议在使用DataSource的许多代码示例中需要任何客户端锁定.因此,即使规范不保证DataSource是线程安全的,也不要求容器供应商提供线程安全的实现,同样,如果 不是"参数,我们别无选择,只能假设DataSource.getConnection不需要其他客户端锁定. ...

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. ...

这篇关于OracleDataSource.getConnection是线程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆