public interface PooledConnection
PooledConnection对象表示与数据源的物理连接。
连接可以在应用程序完成时被重新利用而不是关闭,从而减少了需要进行连接的次数。
应用程序员不直接使用PooledConnection接口; 相反,它被管理池连接的中间层基础结构所使用。
当应用程序调用方法DataSource.getConnection时,它将返回一个Connection对象。 如果连接池正在做的,是Connection对象实际上是一个句柄PooledConnection对象,这是一个物理连接。
连接池管理器(通常是应用程序服务器)维护一个PooledConnection对象的池。 如果池中有一个PooledConnection对象可用,则连接池管理器将返回一个Connection对象,该对象是该物理连接的句柄。 如果没有PooledConnection对象可用,则连接池管理器将呼叫ConnectionPoolDataSource方法getPoolConnection以创建新的物理连接。 实现ConnectionPoolDataSource的JDBC驱动程序创建一个新的PooledConnection对象并返回一个句柄。
当应用程序关闭连接时,它会调用Connection方法close 。 当连接池正在完成时,通知连接池管理器,因为它已使用ConnectionPool方法addConnectionEventListener将其自身注册为ConnectionEventListener对象。 连接池管理停用句柄PooledConnection对象和返回PooledConnection对象,以便它可以再次使用连接池。 因此,当应用程序关闭其连接时,底层物理连接将被回收而不是关闭。
在连接池管理器调用PooledConnection方法close之前,物理连接不会关闭。 通常调用此方法可以有序地关闭服务器,或者如果致命错误使连接无法使用。
连接池管理器通常也是一个语句池管理器,维护一个PreparedStatement对象的池。 当应用程序关闭准备好的语句时,它将调用PreparedStatement方法close 。 当Statement池正在完成时,池管理器被通知,因为它已使用ConnectionPool方法addStatementEventListener自己注册为StatementEventListener对象。 因此,当应用程序关闭其PreparedStatement时,基础准备语句将被回收而不是被关闭。
| Modifier and Type | Method and Description |
|---|---|
void |
addConnectionEventListener(ConnectionEventListener listener)
注册给定的事件侦听器,以便在
PooledConnection对象发生事件时通知它。
|
void |
addStatementEventListener(StatementEventListener listener)
注册一个
StatementEventListener与此
PooledConnection对象。
|
void |
close()
关闭这个
PooledConnection对象所代表的物理连接。
|
Connection |
getConnection()
创建并返回一个
Connection对象,它是对于这个物理连接的手柄
PooledConnection对象表示。
|
void |
removeConnectionEventListener(ConnectionEventListener listener)
从在
PooledConnection对象发生事件时将被通知的组件列表中删除给定的事件侦听器。
|
void |
removeStatementEventListener(StatementEventListener listener)
删除指定的
StatementEventListener从当司机检测到时将获得通知的组件列表
PreparedStatement已关闭或无效。
|
Connection getConnection() throws SQLException
Connection对象,它是对于这个物理连接的手柄PooledConnection对象表示。
当应用程序调用方法DataSource.getConnection并且没有PooledConnection对象可用时,连接池管理器调用此方法。
见interface description以获取更多信息。
Connection对象,这是该
PooledConnection对象的句柄
SQLException - 如果发生数据库访问错误
SQLFeatureNotSupportedException - 如果JDBC驱动程序不支持此方法
void close()
throws SQLException
SQLException - 如果发生数据库访问错误
SQLFeatureNotSupportedException - 如果JDBC驱动程序不支持此方法
void addConnectionEventListener(ConnectionEventListener listener)
PooledConnection对象发生事件时通知它。
listener - 一个组件,通常是连接池管理器,已实现
ConnectionEventListener接口,并希望在连接关闭或有错误时通知
removeConnectionEventListener(javax.sql.ConnectionEventListener)
void removeConnectionEventListener(ConnectionEventListener listener)
PooledConnection对象发生事件时将被通知的组件列表中删除给定的事件侦听器。
listener - 一个组件,通常是连接池管理器,已实现
ConnectionEventListener接口并已将此
PooledConnection对象注册为侦听器
addConnectionEventListener(javax.sql.ConnectionEventListener)
void addStatementEventListener(StatementEventListener listener)
StatementEventListener与此PooledConnection对象。
当要被通知希望组分PreparedStatement由连接创建s的关闭或被检测为无效可使用此方法来注册StatementEventListener与此PooledConnection对象。
listener -它实现了一个部件
StatementEventListener界面,与此登记
PooledConnection对象
void removeStatementEventListener(StatementEventListener listener)
StatementEventListener从当司机检测到时将获得通知的组件列表
PreparedStatement已关闭或无效。
listener - 实现StatementEventListener接口的组件,该
StatementEventListener以前已注册到此
PooledConnection对象
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.