Monday, April 29, 2013

Statement Timeout on a datasource

If your DB takes too long to return data from a JDBC call, you might have STUCK threads.

Using DBMS_LOCK.sleep(seconds => 20); in a stored procedure I have simulated the behaviour of a SLOW DB.

I set a Statement Timeout value of 15 seconds on the Datasource.

value = 15 
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName)

(value is in SECONDS, not in MILLISECONDS)

After 15 seconds I get:

java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation
ORA-06512: at "SYS.DBMS_LOCK", line 205
ORA-06512: at "DEV1_SOAINFRA.PRC_PROCESS", line 17
ORA-06512: at line 1

 at oracle.jdbc.driver.T4CTTIoer.processError(
 at oracle.jdbc.driver.T4CTTIoer.processError(
 at oracle.jdbc.driver.T4C8Oall.processError(
 at oracle.jdbc.driver.T4CTTIfun.receive(
 at oracle.jdbc.driver.T4CTTIfun.doRPC(
 at oracle.jdbc.driver.T4C8Oall.doOALL(
 at oracle.jdbc.driver.T4CCallableStatement.doOall8(
 at oracle.jdbc.driver.T4CCallableStatement.executeForRows(
 at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(
 at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(
 at oracle.jdbc.driver.OraclePreparedStatement.execute(
 at oracle.jdbc.driver.OracleCallableStatement.execute(
 at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(
 at weblogic.jdbc.wrapper.PreparedStatement.execute(
 at oracle.tip.adapter.db.sp.AbstractStoredProcedure.execute(

In alternative, you might also get a java.sql.SQLTimeoutException: ORA-03111: break received on communication channel

I have also added to the Properties of the datasource, and the timeout still occurs at 15 seconds.

I recommend applying also this parameter, useful in case the DB listener is unresponsive.

In fact, setting the Statement Timeout is equivalent to , which allows you to create only 1 Datasource and programmatically set the timeout on a per-query basis:

"Limiting Statement Processing Time with Statement Timeout With the Statement Timeout option on a JDBC data source, you can limit the amount of time that a statement takes to execute on a database connection reserved from the data source. When you set a value for Statement Timeout, WebLogic Server passes the time specified to the JDBC driver using the java.sql.Statement.setQueryTimeout() method. If your JDBC driver does not support this method, it may throw an exception and the timeout value is ignored. When Statement Timeout is set to -1, (the default) statements do not timeout. See the JDBC Data Source: Configuration: Connection Pool page in the Administration Console or see “ JDBCConnectionPoolParamsBean” in the WebLogic Server MBean Reference for more details about this option.

No comments: