[英]tomcat 7 jdbc connection pool and jdbc4 validation
I would like to validate a jdbc connection using tomcat 7 jdbc pool using JDBC4 Connection.isValid instead of a validation Query. 我想使用JDBC4 Connection.isValid而不是验证查询来使用tomcat 7 jdbc池来验证jdbc连接。
I am wondering if implementing a Validator like bellow would be enough. 我想知道实现像下面这样的Validator是否足够。 Also I am wondering which would be a nice timeout. 我也想知道这将是一个不错的超时时间。
Thanks in advance! 提前致谢! Fede 费德
PS: I am using oracle 11g. PS:我正在使用oracle 11g。
public class MyValidator implements Validator{
public static final int DEFAULT_TIMEOUT = 5;
public boolean validate(final Connection c, final int validateAction){
try{
return c.isValid(DEFAULT_TIMEOUT);
}catch(Exception e){
// LOG e
return false;
}
}
A debugger would help you troubleshoot the situation: Tomcat / DBCP connection pools do not return a raw connection but a wrapper/adapter that recycle underlying "true" connections. 调试器将帮助您解决这种情况:Tomcat / DBCP连接池不返回原始连接,而是返回包装底层“真实”连接的包装器/适配器。 The pool usually checks the connections by itself (reconnect if needed) and, I guess, does not allow to really validate. 池通常会自行检查连接(如果需要,请重新连接),而且我猜不允许真正进行验证。
You have more info about the pool validation parameters in the Tomcat doc . 您可以在Tomcat文档中获得有关池验证参数的更多信息。 Another exchange deals about JBoss pools wrapping Oracle connections, what is a common practice. 另一个交易所涉及包装Oracle连接的JBoss池,这是一种常见的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.