Logic: MQ Send -> Update Process_code-> Update Process_code Normal -> MQ.commit () | -> Update Process_code Exception -> Mq.Rollback () Program Probably: mq.send (); connection conn = connectionpool.open () ; if (conn! = null) {Try {conn.setautocommit (false); // execute SQL strings on conn // Changing process_code ... conn.commit (); // mq.commit ();} catch (SQLException EX) {// conn.rollback // mq.rollback (); more process_code failed, MQ sent also rollback ...
}
In general, this is no problem, but if this captured EX is the SQL statement executed when the "Connection Closed" exception generated when calling commit (), ??
At this time, the program is actually an uncertain state.
Connection.commit () This method is logically calculated atomic operation, but it is unreliable because the network is unreliable, so it will never guarantee the commission of database operations and JDBC clients to receive this confirmation in a transaction.
I don't know if this is not a bug of JDBC? (Although this is not avoidable all network procedures)
========================================== 出 出 reason:
I found it with an Oracle database, although Commit throws "Connection Closed" exception, but the executed SQL statement (Change Process_code is 2) has taken effect, the program is in an uncertain state! So I can't basically according to catch Abnormal judgment does the next step (which is MQ. ROLLBACK, or MQ.commit), it is thought that SQLException will appear on mq.rollback (); the result appears process_code = 2 and the data does not send
=================================================== Workaround:
This exception is an exception that appears. By viewing the log, it is found that only once in the test period of approximately two months, the conservative estimate is more than 400,000 data transfer points during this period (there are multiple connections per data transmission. Commit ();)
If there is an abnormality, you can try a few times. As long as there is a COMMIT success, the program can work correctly, only when there is an exception in connection.commit (), the program will be in an uncertain state, then think Process_code update failed, mq.rollback ()