Author: jgomes
Date: Thu Sep 29 18:47:04 2011
New Revision: 1177395

URL: http://svn.apache.org/viewvc?rev=1177395&view=rev
Log:
Add lock of SyncRoot when iterating over the consumers list.
Fixes [AMQNET-342]. (See https://issues.apache.org/jira/browse/AMQNET-342)

Modified:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Session.cs

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs?rev=1177395&r1=1177394&r2=1177395&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/MessageConsumer.cs
 Thu Sep 29 18:47:04 2011
@@ -228,7 +228,7 @@ namespace Apache.NMS.ActiveMQ
 
                                bool wasStarted = this.session.Started;
 
-                               if(wasStarted == true)
+                               if(wasStarted)
                                {
                                        this.session.Stop();
                                }
@@ -236,7 +236,7 @@ namespace Apache.NMS.ActiveMQ
                                listener += value;
                                
this.session.Redispatch(this.unconsumedMessages);
 
-                               if(wasStarted == true)
+                               if(wasStarted)
                                {
                                        this.session.Start();
                                }

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Session.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Session.cs?rev=1177395&r1=1177394&r2=1177395&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Session.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/branches/1.5.x/src/main/csharp/Session.cs
 Thu Sep 29 18:47:04 2011
@@ -824,10 +824,13 @@ namespace Apache.NMS.ActiveMQ
 
         public void Start()
         {
-            foreach(MessageConsumer consumer in this.consumers.Values)
-            {
-                consumer.Start();
-            }
+                       lock(this.consumers.SyncRoot)
+                       {
+                               foreach(MessageConsumer consumer in 
this.consumers.Values)
+                               {
+                                       consumer.Start();
+                               }
+                       }
 
             if(this.executor != null)
             {
@@ -977,13 +980,16 @@ namespace Apache.NMS.ActiveMQ
 
         internal bool IsInUse(ActiveMQTempDestination dest)
         {
-            foreach(MessageConsumer consumer in this.consumers.Values)
-            {
-                if(consumer.IsInUse(dest))
-                {
-                    return true;
-                }
-            }
+                       lock(this.consumers.SyncRoot)
+                       {
+                               foreach(MessageConsumer consumer in 
this.consumers.Values)
+                               {
+                                       if(consumer.IsInUse(dest))
+                                       {
+                                               return true;
+                                       }
+                               }
+                       }
 
             return false;
         }


Reply via email to