[hibernate-commits] Hibernate SVN: r14880 - core/patches/JBOSS_EAP_3_2_4_SP1_CP01_JBPAPP-883/src/org/hibernate/jdbc.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jul 7 09:08:15 EDT 2008


Author: cbredesen
Date: 2008-07-07 09:08:15 -0400 (Mon, 07 Jul 2008)
New Revision: 14880

Modified:
   core/patches/JBOSS_EAP_3_2_4_SP1_CP01_JBPAPP-883/src/org/hibernate/jdbc/AbstractBatcher.java
Log:
JBPAPP-883 explicitly handling ConcurrentModificationException

Modified: core/patches/JBOSS_EAP_3_2_4_SP1_CP01_JBPAPP-883/src/org/hibernate/jdbc/AbstractBatcher.java
===================================================================
--- core/patches/JBOSS_EAP_3_2_4_SP1_CP01_JBPAPP-883/src/org/hibernate/jdbc/AbstractBatcher.java	2008-07-05 19:25:36 UTC (rev 14879)
+++ core/patches/JBOSS_EAP_3_2_4_SP1_CP01_JBPAPP-883/src/org/hibernate/jdbc/AbstractBatcher.java	2008-07-07 13:08:15 UTC (rev 14880)
@@ -8,6 +8,7 @@
 import java.sql.SQLException;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.ConcurrentModificationException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -298,7 +299,9 @@
 			releasing = true;
 
 			try {
-				if (batchUpdate!=null) batchUpdate.close();
+				if ( batchUpdate != null ) {
+					batchUpdate.close();
+				}
 			}
 			catch (SQLException sqle) {
 				//no big deal
@@ -317,10 +320,25 @@
 					// no big deal
 					log.warn("Could not close a JDBC result set", e);
 				}
-				catch (Throwable e) {
-					// sybase driver (jConnect) throwing NPE here in certain cases
-					log.warn("Could not close a JDBC result set", e);
+				catch ( ConcurrentModificationException e ) {
+					// this has been shown to happen occasionally in rare cases
+					// when using a transaction manager + transaction-timeout
+					// where the timeout calls back through Hibernate's
+					// registered transaction synchronization on a separate
+					// "reaping" thread.  In cases where that reaping thread
+					// executes through this block at the same time the main
+					// application thread does we can get into situations where
+					// these CMEs occur.  And though it is not "allowed" per-se,
+					// the end result without handling it specifically is infinite
+					// looping.  So here, we simply break the loop
+					log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
+					break;
 				}
+				catch ( Throwable e ) {
+					// sybase driver (jConnect) throwing NPE here in certain
+					// cases, but we'll just handle the general "unexpected" case
+					log.warn( "Could not close a JDBC result set", e );
+				}
 			}
 			resultSetsToClose.clear();
 
@@ -329,6 +347,11 @@
 				try {
 					closeQueryStatement( (PreparedStatement) iter.next() );
 				}
+				catch ( ConcurrentModificationException e ) {
+					// see explanation above...
+					log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
+					break;
+				}
 				catch (SQLException e) {
 					// no big deal
 					log.warn("Could not close a JDBC statement", e);




More information about the hibernate-commits mailing list