dbcp如何设置连接超时?

bineon 2007-06-04 05:12:04
这个是一个获取DataSource的例子程序,请问如何设置超时呢?
public static DataSource setupDataSource(String connectURI) {
//
// First, we'll need a ObjectPool that serves as the
// actual pool of connections.
//
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
ObjectPool connectionPool = new GenericObjectPool(null);

//
// Next, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string passed in the command line
// arguments.
//
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);

//
// Now we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
//
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);

//
// Finally, we create the PoolingDriver itself,
// passing in the object pool we created.
//
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

return dataSource;
}
...全文
689 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
superlyq006 2007-06-18
  • 打赏
  • 举报
回复
设置数据源的removeAbandoned="true",removeAbandonedTimeout="60",logAbandoned="true"几个属性就可以了。
DBCP会自动把超过timeout时间仍未关闭的连接强制关闭,并且打出异常信息(包含打开连接的代码位置)。

bineon 2007-06-08
  • 打赏
  • 举报
回复
upup。求人帮助。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧