activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r830001 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs
Date Mon, 26 Oct 2009 22:21:14 GMT
Author: tabish
Date: Mon Oct 26 22:21:14 2009
New Revision: 830001

URL: http://svn.apache.org/viewvc?rev=830001&view=rev
Log:
Fix faulty shutdown logic.  

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs?rev=830001&r1=830000&r2=830001&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs
Mon Oct 26 22:21:14 2009
@@ -43,14 +43,10 @@
             this.task = task;
 
             this.theThread = new Thread(Run);
+            this.theThread.IsBackground = true;
             this.theThread.Start();
         }
 
-        ~DedicatedTaskRunner()
-        {
-            this.Shutdown();
-        }
-
         public void Shutdown(TimeSpan timeout)
         {
             lock(mutex) 
@@ -62,16 +58,16 @@
 
                 // Wait till the thread stops ( no need to wait if shutdown
                 // is called from thread that is shutting down)
-                if(!this.terminated) 
+                if(Thread.CurrentThread != this.theThread && !this.terminated) 
                 {
                     Monitor.Wait(this.mutex, timeout);
                 }
-            }            
+            }
         }
 
         public void Shutdown()
         {
-            this.Shutdown(new TimeSpan(Timeout.Infinite));
+            this.Shutdown(TimeSpan.FromMilliseconds(-1));
         }
 
         public void Wakeup()
@@ -101,6 +97,7 @@
                         
                         if(this.shutdown)
                         {
+                            
                             return;
                         }
                     }
@@ -126,13 +123,15 @@
             catch
             {
             }
-        
-            // Make sure we notify any waiting threads that thread
-            // has terminated.
-            lock(this.mutex)
-            {
-                this.terminated = true;
-                Monitor.PulseAll(this.mutex);
+            finally
+            {        
+                // Make sure we notify any waiting threads that thread
+                // has terminated.
+                lock(this.mutex)
+                {
+                    this.terminated = true;
+                    Monitor.PulseAll(this.mutex);
+                }
             }
         }
     }



Mime
View raw message