The following sql on the eve of 618 in 2014:
<!--Add sync data--> <insert id="insert" parameterClass="order"> INSERT INTO aa(ID,ORDERID,CREATEDATE) VALUES (seq.Nextval,#orderId#,#createDate#) <selectKey resultClass="java.lang.Long"> SELECT seq.CURRVAL FROM DUAL </selectKey> </insert>
Will throw more than 800 errors as follows
Caused by: java.sql.SQLException: ORA-01013: user requested to cancel the current operation at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219) at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:970)
The reason is that the sql execution time is too long, and the jdbc driver actively cancels the operation.
suggestion:
1. Look at the average execution time of the sql and set a timeout for the sql. (Too long execution time will occupy the connection, causing others to not get the connection)
2. Ask the DBA if there is a way to optimize the SQL, such as whether it can be inserted in parallel. Or can do partition.
1. Data source configuration
If you use apache dbcp and may encounter a bottleneck in the number of connections, you can adjust the following configuration:
<!—It is recommended that the following values be the same as possible, and there is no need to frequently expire idle connections (unless, for example, connection pool resources are scarce, which can be considered) -->
<property name="maxIdle" value="80" />
<property name="minIdle " value="80" />
<property name="initialSize" value="80"/>
<property name="maxActive" value="80" />
<!—This is the time to wait to obtain the connection pool connection, and it should not be too large. For example, set it at 500 milliseconds-->
<property name="maxWait" value="500" />
<!-- Remove unreferenced connections (those without close connections) set to false here, you need to ensure that the connection in the program must be released -->
<property name="removeAbandoned" value="false"></property>
<property name="removeAbandonedTimeout" value="300000"></property>
<!-- how long a connection is idle to remove from the pool, here Don't judge -->
<property name="minEvictableIdleTimeMillis" value="-1" />
<!-- How many times to cycle the test when it expires (0 is equivalent to closing the timer) -->
<property name="numTestsPerEvictionRun" value="0" />
<!-- expire connection timer period-->
<property name="timeBetweenEvictionRunsMillis" value="120000" />
<!-- Whether to test when the connection is idle, that is, keep the connection alive, use it with the expire connection timer -->
<property name="testWhileIdle" value="false"></property>
If it is a mysql library, there may be a problem of 8 hours. You can consider opening the expiration timer (numTestsPerEvictionRun=1), and periodically expire the connection. The timeBetweenEvictionRunsMillis time can be set to about 8 hours.
In addition, the socket connection/read timeout can be configured by the following configuration:
<property name="connectionProperties"
value="oracle.net.CONNECT_TIMEOUT=2000;oracle.jdbc.ReadTimeout=2000"></property>
(The connection and read timeout time here, please consider the size according to your own business)
For specific configuration, please refer to: http://www.importnew.com/2466.html
2, ibatis configuration
**The project is using ibatis-sqlmap-2.3.4.726.jar version, and since 2.3.1:
o Removed maxTransactions, maxRequests, maxSessions from configuration, all are now controlled by the resource providers。(即已经移除了maxTransactions, maxRequests, maxSessions配置)
So we only need the following configuration:
<settings cacheModelsEnabled="false" enhancementEnabled="true"
lazyLoadingEnabled="false" errorTracingEnabled="true" maxRequests="32"
defaultStatementTimeout="2"/>
The defaultStatementTimeout unit is seconds; according to business configuration.
If you want to only set the timeout of a certain Statement, you can consider: <insert ......timeout="2">
The following error was reported online before, because the statement execution timed out.
Cause: java.sql.SQLException: ORA-01013: user requested to cancel the current operation
3, spring transaction manager configuration
Provide a global transaction-level timeout:
<bean id="oracleTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="oracleDataSource" />
<property name="defaultTimeout" value="2"/>
</bean>
Summarize:
The main timeout settings are as follows:
1. Connection timeout
2. Timeout of reading data
3. Statement timeout
4. Transaction-level timeout = N* Statement timeout + GC pause time
Some problems with transaction timeouts have been summarized before. If you are interested, you can refer to the following:
http://jinnianshilongnian.iteye.com/blog/1986023
http://www.importnew.com/2466.html