JDBC getConnection超时问题 [英] JDBC getConnection timeout issue

查看:399
本文介绍了JDBC getConnection超时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用连接池从Oracle9i 9.2.0.4版数据库获取数据库连接的应用程序.应用程序托管在SJSAS 8.1中,驱动程序为ojdbc14.jar版本10.1.0.4.

I have an application that uses connection pooling to get database connection from an Oracle9i release 9.2.0.4 database. Application is hosted in SJSAS 8.1 and the driver is ojdbc14.jar version 10.1.0.4.

我遇到的问题是datasource.getConnection()方法需要大约40秒才能在数据库关闭时引发异常!这导致应用程序在数据库中断期间过载.我尝试使用数据源设置LoginTimeout=8,但是没有效果.

The problem I'm having is datasource.getConnection() method is taking about 40 secs to throw an exception when the DB is down! This is causing the application to get overloaded during a DB outage. I tried setting LoginTimeout=8 with the datasource but it has no effect.

请在下面查看我正在使用的数据源

Please see below the datasource I'm using

<jdbc-connection-pool connection-validation-method="table" 
                      datasource-classname="oracle.jdbc.pool.OracleDataSource" 
                      fail-all-connections="true" 
                      idle-time out-in-seconds="600" 
                      is-connection-validation-required="true" 
                      is-isolation-level-guaranteed="false" 
                      max-pool-size="100" 
                      max-wait-time-in-millis="8000" 
                      name="mydb" 
                      pool-resize-quantity="80" 
                      res-type="javax.sql.DataSource" 
                      steady-pool-size="20" 
                      validation-table-name="dual">
    <property name="url" value="jdbc:oracle:thin:@server1:1521:mydb"/>
    <property name="user" value="user1"/>
    <property name="LoginTimeout" value="8"/>
    <property name="password" value="pass1"/>
</jdbc-connection-pool>

任何人都可以帮忙吗?我需要getConnection()方法在给定的超时时间内超时.

Can any one please help? I need the getConnection() method to timeout with in the timeout given.

推荐答案

以下是一些尝试:

摘自《Oracle®数据库JDBC开发人员指南和参考》.

From "Oracle® Database JDBC Developer's Guide and Reference".

将JDBC与防火墙配合使用

Using JDBC with Firewalls

空闲连接的防火墙超时可能会切断连接.这可能会导致JDBC应用程序在等待连接时挂起.您可以执行以下一项或多项操作,以避免由于防火墙超时而断开连接:

Firewall timeout for idle-connections may sever a connection. This can cause JDBC applications to hang while waiting for a connection. You can perform one or more of the following actions to avoid connections from being severed due to firewall timeout:

  • 如果使用连接缓存 或连接池,然后总是 将不活动超时值设置为 连接缓存要短一些 比防火墙的空闲超时值.
  • oracle.net.READ_TIMEOUT作为 连接属性以启用读取 套接字超时.超时值 以毫秒为单位.
  • 对于JDBC OCI和JDBC Thin 驱动程序,使用net描述符 连接到数据库并指定 中的ENABLE = BROKEN参数 连接中的DESCRIPTION子句 描述符.另外,设置一个较低的值 用于tcp_keepalive_interval.
  • 通过设置启用Oracle Net DCD SQLNET.EXPIRE_TIME=1在 服务器端的sqlnet.ora文件.
  • If you are using connection caching or connection pooling, then always set the inactivity timeout value on the connection cache to be shorter than the firewall idle timeout value.
  • Pass oracle.net.READ_TIMEOUT as connection property to enable read timeout on socket. The timeout value is in milliseconds.
  • For both JDBC OCI and JDBC Thin drivers, use net descriptor to connect to the database and specify the ENABLE=BROKEN parameter in the DESCRIPTION clause in the connect descriptor. Also, set a lower value for tcp_keepalive_interval.
  • Enable Oracle Net DCD by setting SQLNET.EXPIRE_TIME=1 in the sqlnet.ora file on the server-side.

这篇关于JDBC getConnection超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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