`
can_do
  • 浏览: 245782 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

连接池相关知识点||about database connection pool

阅读更多
0、javax.sql.PooledConnection
1、connection pooling(连接缓冲)=>database connection pool(数据库连接池)=>database physical connection(物理连接)||long connection(长连接)
2、Connection(数据库连接)-->Statement(会话声明)-->Resultset(结果游标)
3、  1 Connection=>n Statements
4、Database Connection Pool=>I、PoolSize,限制应用或系统可拥有的最大资源(对数据库资源的保护);II、在PoolSize中,最大限度的使用连接资源(充分利用发挥数据库的有效资源);III、封闭操作:申请、释放、回收、共享和同步
5、ConnectionPoolManager=>method close=>Closes the physical connection that this PooledConnection object represents
连接池管理器的close方法关闭的是一个物理连接。
6、Thus, when an application closes its connection, the underlying physical connection is recycled rather than being closed.
然后(在使用数据源时),应用系统(web应用)中调用的close方法,关闭的是逻辑连接,即连接池管理器会将在用的连接变为空闲,也就是回收连接,以供其他客户端再次使用该连接。一般的应用代码如下:

********begin********

Connection conn = ds.getConnection();
rs.close();
stmt.close();
conn.close();

********end***********


7、The physical connection is not closed until the connection pool manager calls the PooledConnection method close. This method is generally called to have an orderly shutdown of the server or if a fatal error has made the connection unusable.
物理连接一般不会被关闭(即长连接),直到连接池管理器调用了PooledConnection的close方法。该方法的调用一般是在应用服务器(中间件)正常关闭时或者遇到致命的错误时,才会将连接置为不可用,即关闭物理连接。

7.1、JDBC只提供了最直接的数据库操作规范,对数据库资源管理,如:对物理连接的管理及缓冲,期望第三方应用服务器(Application Server)的提供。
7.2、200(connections)* 250(statements)=50000(statement)
7.3、应用服务器以oracle(或其他数据库)为数据源时,数据库提供的物理连接最大数由process决定,如果连接同一数据库的数据源有N个,则N个数据源连接池的最大(物理)连接数的总和不能超过process,实际上还有一部分物理连接为预留的,应该不超过process*90%。

查询由数据源连接池创建的物理连接数:

-- for v$session
select count(a.program) as session_number
   from v$session a
  where a.USERNAME = 'CAN_DO'
    AND a.PROGRAM like '%Thin%';


-- for v$process
select count(*) as physical_connection from v$process;

parameter process =150 >= physical_connection >= session_number,

其中session_number数为实际通过中间件的数据源连接池所创建的物理连接数量。

7.4、From Oracle:
(1).1个connection可以有0,1,N个session
(2).1个session可以对应0,1个connection

*******************************************************

8、Transaction=>Local Transaction 和 Global Transaction(distributed transaction)。
9、XA=> prepare 和 commit.
10、weblogic=>TxDataSource=> EnableTwoPhaseCommit=true.
11、XA driver<==>non-XA driver
12、XA connection pool<==>non-XA connection pool
13、distributed transaction
14、prepare=>commit=>rollback
15、non-XA =>transactions must be single-database
16、XA=>distributed transactions
17、2PC(protocol)=>Two Phase Commit
18、根据规范,在Global Transaction中,non-XA数据源可以用,但是要配置成2PC,并且最多只能有1个non-XA数据源。当有2个及以上的non-XA connection pool时,
应用服务器就会抛异常,类似:"java.sql.SQLException: Connection has already been created in this tx context for pool named <first pool's name>. Illegal attempt to create connection from another pool: <second pool's name>"

19、getConnection =>connection handle (连接句柄,作为物理连接的代理,多个连接句柄可以共享同一个物理连接,前提是shareable资源)< logical connection and CM> => physical connection。

【温馨提示】
如果您觉得满意,可以选择支持下,您的支持是我最大的动力:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics