关于问题org.apache.commons.dbcp.BasicDataSource [英] Question regarding org.apache.commons.dbcp.BasicDataSource

查看:633
本文介绍了关于问题org.apache.commons.dbcp.BasicDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的固定与我们使用的BasicDataSource虽然我理解它的一部分我还有一些问题没有解决的方式了一些bug:)

I fixed some bug related to the way we were using BasicDataSource and though I understand part of it I still have some questions unanswered :)

问题:
应用程序无法分贝故障之后自动连接到数据库。

Problem: The application was not able to auto-connect to the database after a db failure.

应用程序正在使用 org.apache.commons.dbcp .BasicDataSource类作为一个JDBC连接到Oracle数据库一个​​TCP连接池。

Application is using org.apache.commons.dbcp.BasicDataSource class as a TCP-connection pool for a JDBC connection to Oracle db.

修正:
经过一番研究,我发现在的BasicDataSource testOnBorrow和testOnreturn未设置。我公司提供的验证查询到测试连接。这解决了这一问题。

Fix: After some research I discovered that in BasicDataSource testOnBorrow and testOnreturn were not set. I provided the validation query to test connections. This fixed the problem

马克斯没有在池中的连接设置为1

Max no of connections in pool was set to 1

我的理解:
连接池将移交给应用程序的连接。
我觉得是发生在应用程序的神奇返回坏收集到池时,它DB坠毁。现在,因为池不知道这是否是一个坏的连接,将移交给下一个需要它导致应用程序不会自动重新连接到数据库一次应用程序相同的连接。

My Understanding: The connection pool would hand over a connection to the application. What I think was happening was the application MAGICALLY returned the bad collection to the pool when it db crashed . Now since the Pool does not know if it is a bad connection it would hand over the same connection to the application next time it needs it causing the application to not auto-reconnect to db.

现在,经过修复..每当一个糟糕的连接被返回到连接池,将被丢弃,不会再被使用,因为我上面所做的修复。

Now, after the fix.. whenever a bad connection is returned to the connection pool it would be discarded and wont be used again because of the fix I made above.

现在我知道的BasicDataSource包装给人以应用程序,例如,每当应用程序说con.close ..BasicDataSource会知道的连接没有使用,也可以返回到连接任何更多..很会照顾之前的连接游泳池或discardigg等。

Now I know that BasicDataSource wraps the connection before giving to the application, such that whenever application says con.close ..BasicDataSource would know that the connection is not used any more.. it will take care of either returning the connection to the pool or discardigg etc.

悬而未决的问题:
但我不明白是什么使应用程序的神奇返回到连接池时,它的连接中断[注当连接退出非正常不叫了con.close方法。有没有办法的BasicDataSource就知道该连接关闭或存在的?有人能指出我到code是什么?

Unanswered Question: However what I do not understand is what makes the application MAGICALLY return the connection to the connection pool when its broken[Note that con.close method is not called when the connection exits un-gracefully]. There is no way of BasicDataSource to know that the connection closed or there is ?. Can someone point me to code for that ?

我在我的整体理解为什么修复工作连接??

I my overall understanding connect of why the fix worked ??

推荐答案

现在,我知道这是种古老的线程,但它的高在谷歌的搜索结果,所以我想我可能给它一个快速的答案。有关配置的BasicDataSource的更多信息,你应该引用DBCP配置页:的http:/ /commons.apache.org/proper/commons-dbcp/configuration.html

Now, I know that this is kind of an old thread, but it's high on google search results, so I thought I might give it a quick answer. For more information on configuring the BasicDataSource, you should reference the DBCP Configuration page: http://commons.apache.org/proper/commons-dbcp/configuration.html

要回答的unanaswered问题的BasicDataSource怎么知道当连接abondoned,需要返回到连接池? (意译)...

To answer the "unanaswered" question of "How does BasicDataSource know when a connection is abondoned and needs to be returned to the connection pool?" (paraphrased)...

org.apache.commons.dbcp.BasicDataSource能够监视它提供了通过使用包装类连接的连接流量和使用。每次调用连接或从连接创建的任何报表上的方法时,你实际上调用实现一个接口或一个具有相同的方法扩展基类的包装类(多态性万岁!)。这些自定义的方法让数据源知道一个连接是否有效。

org.apache.commons.dbcp.BasicDataSource is able to monitor traffic and usage on the connections it offers by using a wrapper class for the Connection. Every time you call a method on the connection or any Statements created from the connection, you are actually calling a wrapper class that implements an interface or extends a base class with those same methods (Hurray for Polymorphism!). These custom methods allow the DataSource to know whether or not a Connection is active.

在所述的BasicDataSource本身,有一个被称为removeAbandoned,另一个称为removeAbandonedTimeout属性,用于配置返回到连接池abondonded连接的这种行为。

On the BasicDataSource itself, there is a property called "removeAbandoned" and another called "removeAbandonedTimeout" that are used to configure this behavior of returning abondonded connections to the connection pool.

removeAbandoned是指被遗弃的连接是否应该返回到池中一个布尔值。默认为假。

"removeAbandoned" is a boolean that indicates whether abandoned connections should be returned to the pool. Defaults to "false".

removeAbandonedTimeout是一个int,那应该被允许之前被认为是一个连接被遗弃传递闲置秒重新presents数。默认值是300(约5分钟)。

"removeAbandonedTimeout" is an int, that represents the number of seconds of inactivity that should be allowed to pass before a connection is considered to be abandoned. Default value is 300 (about 5 minutes).

这篇关于关于问题org.apache.commons.dbcp.BasicDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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