简体   繁体   中英

how long can Spring JdbcTemplate wait for an oracle stored procedure to finish

my java code is like:

logger.info("start");
getJdbcTemplate().execute("call " + procedureName + "()");  

and I got the exception:

org.springframework.dao.DataAccessResourceFailureException: StatementCallback; SQL [call PRMI_UPDATE_USER_LOGIN_INFO()]; Io ERROR: Connection reset; nested exception is java.sql.SQLException: Io ERROR: Connection reset
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:257)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:428)

Maybe it's caused by the long time waiting. I found that it printed " start " in log and after about 5 minutes I got the exception.

update at 2013-03-13:

I got that exception not only at calling oracle stored procedure but at druid's 'JdbcUtil.close(...)':

com.alibaba.druid.util.JdbcUtils.close:81 - close connection error
java.sql.SQLRecoverableException: Io Error: Connection reset
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:521)
    at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:500)
    at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3509)
    at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:167)
    at com.alibaba.druid.filter.stat.StatFilter.connection_close(StatFilter.java:254)
    at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:163)
    at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.close(ConnectionProxyImpl.java:115)
    at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:79)
    at com.alibaba.druid.pool.DruidDataSource.shrink(DruidDataSource.java:1876)
    at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:1694)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at oracle.net.ns.DataPacket.send(DataPacket.java:150)
    at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:180)
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:169)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:117)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:92)
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:77)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1034)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1010)
    at oracle.jdbc.driver.T4C7Ocommoncall.receive(T4C7Ocommoncall.java:97)
    at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:487)

The druid's JdbcUtil.close method is quite simple:

 public static void close(Connection x) {
    if (x == null) {
        return;
    }
    try {
        x.close();
    } catch (Exception e) {
        LOG.debug("close connection error", e);
    }
}

the source code is : https://github.com/alibaba/druid/blob/master/src/main/java/com/alibaba/druid/util/JdbcUtils.java

It should wait as long as it is needed. Forget about various hacks which try to "detect" deadlock based on timeout delay.

  • you should find also some ORA-XXXX error. Io ERROR: Connection reset does not look like Oracle error message, there should be some error number attached to it
  • the timeout 5 minutes is very strange value. Theoretically this can be setup also on database side. As profile parameter CPU_PER_CALL but in such a case you should get an error: ORA-02393: exceeded call limit on CPU usage . And you connection should NOT be lost
  • theoretically you can also have problems which dead connection detection, but 5 minutes timeout is too short for that
  • another possible source can be ORA-600 error. Oracle internal error, maybe your session process crashed and therefore TCP connection was lost
  • you should contact your local DBAs and ask then for cooperation. They should help you better than anonymous people on the Internet forum.

Maybe it's caused by the long time waiting

No it is not caused due to that

As Java Doc says about DataAccessResourceFailureException

Data access exception thrown when a resource fails completely: for example, if we can't connect to a database using JDBC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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