java c3p0.idle_test_period 的使用。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10175957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The use of c3p0.idle_test_period.
提问by TU_HEO DAKAI
I'm new to c3op, and confused about the use of :
我是 c3op 的新手,对以下的使用感到困惑:
c3p0.idle_test_period
In this link : HowTo configure the C3P0 connection pool
在此链接中:如何配置 C3P0 连接池
idleTestPeriod : Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default:
0, If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out
connections, every this number of seconds.
What is the purpose of this kind of test (idel, pooled connections), and the relationship between c3p0.idle_test_period and c3p0.timeout?
这种测试的目的是什么(idel,pooled connection),c3p0.idle_test_period和c3p0.timeout的关系是什么?
回答by MartinK
The database server may close a connection on its side after a certain amount of time - causing some error in your application, because it'll attempt to send a query on a connection which is no longer available on the server side.
数据库服务器可能会在一段时间后关闭其一侧的连接 - 导致您的应用程序出现一些错误,因为它会尝试在服务器端不再可用的连接上发送查询。
In order to avoid this you can let the pool periodically check a connection (Think of a ping) for it's validity. This is what idle_test_period
is for.
为了避免这种情况,您可以让池定期检查连接(想想 ping)的有效性。这idle_test_period
就是为了。
timeout
is the timespan after which the pool will remove a connection from the pool, because the connection wasn't checked out (used) for a while and the pool contains more connections than c3pO.min_size
.
timeout
是池将从池中删除连接的时间跨度,因为该连接有一段时间未检出(使用)并且池包含的连接数多于c3pO.min_size
.
回答by anand kadu
I think this setting is used in hibernate in order to validate pooled connection after every few seconds . Consider a scenario if on database side, password is changed. Hibernate already pooled connections on old password. So it is security breach having pool with wrong password.So when hibernate will validate after few seconds it . It will invalidate that pooled connection.
我认为此设置用于休眠状态,以便每隔几秒验证一次池连接。考虑一个场景,如果在数据库端,密码被更改。Hibernate 已经在旧密码上汇集了连接。因此,池中的密码错误是安全漏洞。所以几秒钟后休眠将验证它。它将使该池连接无效。