[jboss-cvs] JBossAS SVN: r64904 - branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jms/inflow.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 04:57:11 EDT 2007


Author: adrian at jboss.org
Date: 2007-08-28 04:57:11 -0400 (Tue, 28 Aug 2007)
New Revision: 64904

Modified:
   branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivation.java
Log:
[JBAS-4640] - Avoid multiple threads in the reconnect

Modified: branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivation.java
===================================================================
--- branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivation.java	2007-08-28 08:56:37 UTC (rev 64903)
+++ branches/Branch_4_2/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivation.java	2007-08-28 08:57:11 UTC (rev 64904)
@@ -78,6 +78,9 @@
    
    /** Whether delivery is active */
    protected SynchronizedBoolean deliveryActive;
+
+   // Whether we are in the failure recovery loop
+   private SynchronizedBoolean inFailure = new SynchronizedBoolean(false);
    
    /** The jms provider adapter */
    protected JMSProviderAdapter adapter;
@@ -222,41 +225,52 @@
       deliveryActive.set(false);
       teardown();
    }
-
+   
    /**
     * Handles any failure by trying to reconnect
+    * 
+    * @param failure the failure 
     */
    public void handleFailure(Throwable failure)
    {
       log.warn("Failure in jms activation " + spec, failure);
       
-      while (deliveryActive.get())
+      // Only enter the failure loop once
+      if (inFailure.set(true))
+         return;
+      try
       {
-         teardown();
-         try
+         while (deliveryActive.get())
          {
-            Thread.sleep(spec.getReconnectIntervalLong());
-         }
-         catch (InterruptedException e)
-         {
-            log.debug("Interrupted trying to reconnect " + spec, e);
-            break;
-         }
+            teardown();
+            try
+            {
+               Thread.sleep(spec.getReconnectIntervalLong());
+            }
+            catch (InterruptedException e)
+            {
+               log.debug("Interrupted trying to reconnect " + spec, e);
+               break;
+            }
 
-         log.info("Attempting to reconnect " + spec);
-         try
-         {
-            setup();
-            log.info("Reconnected with messaging provider.");            
-            break;
+            log.info("Attempting to reconnect " + spec);
+            try
+            {
+               setup();
+               log.info("Reconnected with messaging provider.");            
+               break;
+            }
+            catch (Throwable t)
+            {
+               log.error("Unable to reconnect " + spec, t);
+            }
          }
-         catch (Throwable t)
-         {
-            log.error("Unable to reconnect " + spec, t);
-         }
-         
-
       }
+      finally
+      {
+         // Leaving failure recovery loop
+         inFailure.set(false);
+      }
    }
 
    public void onException(JMSException exception)
@@ -401,6 +415,7 @@
     */
    protected void teardownDestination()
    {
+      destination = null;
    }
    
    /**
@@ -605,6 +620,7 @@
       {
          log.debug("Error clearing the pool " + pool, t);
       }
+      pool = null;
    }
 
    /**




More information about the jboss-cvs-commits mailing list