[jboss-svn-commits] JBL Code SVN: r26845 - labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jun 5 04:48:04 EDT 2009


Author: adinn
Date: 2009-06-05 04:48:04 -0400 (Fri, 05 Jun 2009)
New Revision: 26845

Modified:
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
Log:
corrected synchronized blocks in shutdown code to use the right synchronization objects fixes JBTM-564

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2009-06-05 02:46:14 UTC (rev 26844)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2009-06-05 08:48:04 UTC (rev 26845)
@@ -841,7 +841,7 @@
 
 		        return true;
 		    }
-                }
+        }
 	}
 
     /**
@@ -955,7 +955,9 @@
 
 	private final void shutdown (boolean waitForTransactions)
 	{
-	    synchronized (_shutdownLock)
+        // the reaper thread synchronizes and waits on this
+
+	    synchronized (this)
 	    {
 	        _inShutdown = true;
 
@@ -987,71 +989,64 @@
 	        {
 	            try
 	            {
-	                _shutdownLock.wait();
+	                this.wait();
 	            }
 	            catch (final Exception ex)
 	            {
 	            }
 	        }
 
-	        synchronized (_reaperThread)
-	        {
-	            _reaperThread.shutdown();
-	            _reaperThread.interrupt();  // by this stage there should be no transactions left anyway.
 
-	            synchronized (this)
-	            {
-	                notifyAll();
-	            }
+            _reaperThread.shutdown();
 
-	            try
-	            {
-	                _reaperThread.join();
-	            }
-	            catch (final Exception ex)
-	            {
-	            }
-	        }
+            notifyAll();
+        }
+        try
+        {
+            _reaperThread.join();
+        }
+        catch (final Exception ex)
+        {
+        }
 
-	        _reaperThread = null;
+        _reaperThread = null;
 
-	        _reaperWorkerThread.shutdown();
+        // the reaper worker thread synchronizes and wais on the work queue
 
-	        synchronized (_reaperWorkerThread)
-	        {
-	            try
-	            {
-	                _reaperWorkerThread.interrupt();
-	                _reaperWorkerThread.join();
-	            }
-	            catch (final Exception ex)
-	            {
-	            }
-	        }
+        synchronized(_workQueue) {
+            _reaperWorkerThread.shutdown();
+            _workQueue.notifyAll();
+            // hmm, not sure we really need to do this but . . .
+            _reaperWorkerThread.interrupt();
+        }
 
-	        _reaperWorkerThread = null;
+        try
+        {
+            _reaperWorkerThread.join();
+        }
+        catch (final Exception ex)
+        {
+        }
 
-	        _inShutdown = false;
-	    }
+        _reaperWorkerThread = null;
 	}
 
 	/*
 	 * Remove element from list and trigger waiter if we are
 	 * being shutdown.
+	 *
+	 * n.b. must only be called when synchronized on this
 	 */
 
 	private final void removeElement (ReaperElement e)
 	{
-	    synchronized (_shutdownLock)
-	    {
-                _timeouts.remove(e._control);
-                _transactions.remove(e);
+        _timeouts.remove(e._control);
+        _transactions.remove(e);
 
-	        if (_inShutdown && (_transactions.size() == 0))
-	        {
-	            _shutdownLock.notifyAll();
-	        }
-	    }
+        if (_inShutdown && (_transactions.size() == 0))
+        {
+            this.notifyAll();
+        }
 	}
 
 	/**
@@ -1260,7 +1255,7 @@
 	 * the transactions.
 	 */
 
-	public static void terminate (boolean waitForTransactions)
+	public static synchronized void terminate (boolean waitForTransactions)
 	{
 	    if (_theReaper != null)
 	    {
@@ -1331,10 +1326,5 @@
 
 	private static int _zombieCount = 0;
 
-	/*
-	 * Shutdown lock.
-	 */
-
-	private static final Object _shutdownLock = new Object();
-	private static boolean _inShutdown = false;
+	private boolean _inShutdown = false;
 }




More information about the jboss-svn-commits mailing list