简体   繁体   English

JDBC getConnection超时问题

[英]JDBC getConnection timeout issue

I have an application that uses connection pooling to get database connection from an Oracle9i release 9.2.0.4 database. 我有一个使用连接池从Oracle9i 9.2.0.4版数据库获取数据库连接的应用程序。 Application is hosted in SJSAS 8.1 and the driver is ojdbc14.jar version 10.1.0.4. 应用程序托管在SJSAS 8.1中,驱动程序是ojdbc14.jar 10.1.0.4版。

The problem I'm having is datasource.getConnection() method is taking about 40 secs to throw an exception when the DB is down! 我遇到的问题是,当数据库关闭时, datasource.getConnection()方法大约需要40秒才能引发异常! 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. 我尝试使用数据源设置LoginTimeout=8 ,但没有任何效果。

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>

Can any one please help? 有人可以帮忙吗? I need the getConnection() method to timeout with in the timeout given. 我需要使用getConnection()方法在给定的超时时间内超时。

Here's a few things to try: 这里有一些尝试:

From "Oracle® Database JDBC Developer's Guide and Reference". 摘自《Oracle®数据库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. 这可能会导致JDBC应用程序在等待连接时挂起。 You can perform one or more of the following actions to avoid connections from being severed due to firewall timeout: 您可以执行以下一项或多项操作,以避免由于防火墙超时而断开连接:

  • 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. 传递oracle.net.READ_TIMEOUT作为连接属性以启用套接字上的读取超时。 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. 对于JDBC OCI和JDBC Thin驱动程序,请使用net描述符连接到数据库,并在connect描述符的DESCRIPTION子句中指定ENABLE = BROKEN参数。 Also, set a lower value for tcp_keepalive_interval . 另外,为tcp_keepalive_interval设置一个较低的值。
  • Enable Oracle Net DCD by setting SQLNET.EXPIRE_TIME=1 in the sqlnet.ora file on the server-side. 通过在服务器端的sqlnet.ora文件中设置SQLNET.EXPIRE_TIME=1来启用Oracle Net DCD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM