与Oracle的单一连接 [英] Single connection with Oracle

查看:89
本文介绍了与Oracle的单一连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,开发人员使用 Connection的单个实例,而不是 Oracle 12c 上的连接池.

In my project, developers use a single instance of Connection instead of a connection pool on an Oracle 12c.

使用池是一种常见的做法,Oracle自己对其进行了记录: http://docs.oracle.com/database/121/JJUCP/get_started.htm#JJUCP8120 .

Using a pool is a common practice and Oracle itself documents it: http://docs.oracle.com/database/121/JJUCP/get_started.htm#JJUCP8120.

但是 JDBC 4.2规范表示:

13.1.1创建语句

13.1.1 Creating Statements

每个Connection对象可以创建多个Statement对象,程序可以同时使用它们.

Each Connection object can create multiple Statement objects that may be used concurrently by the program.

如果可以使用语句来管理并发,为什么要使用连接池而不是单个连接?

Why using a pool of connections instead of a single connection, if it's possible to use statements to manage concurrency?

推荐答案

Oracle数据库开发团队强烈劝阻,在多个线程中使用单个Connection.这几乎总是会引起问题.通常,我们不会考虑任何这样做的问题报告.

The Oracle Database Dev Team strongly discourages using a single Connection in multiple threads. That almost always causes problems. As a general rule we will not consider any problem report that does this.

一个连接可以一次打开多个语句和/或结果集,但一次只能执行一个.连接严格是单线程和阻塞的.我们尝试阻止多个线程同时访问Connection,但是在少数情况下,这是可能的.这些几乎可以保证会引起问题. (主要出于性能原因,修复或防止这些情况不切实际.只是不要在多个线程之间共享单个Connection.)

A Connection can have multiple Statements and/or ResultSets open at one time but only one can execute at a time. Connections are strictly single threaded and blocking. We try to prevent multiple threads from accessing a Connection simultaneously but there are a few odd cases where it is possible. These are all but guaranteed to cause problems. (It is not practical to fix or prevent these cases mostly for performance reasons. Just don't share a single Connection across multiple threads.)

这篇关于与Oracle的单一连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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