Author: gatfora
Date: Wed Oct  3 02:50:18 2007
New Revision: 581547

URL: http://svn.apache.org/viewvc?rev=581547&view=rev
Log:
Close timing window when stopping SandeshaThreads and another thread requesting 
that it starts.

Modified:
    
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/SandeshaThread.java

Modified: 
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/SandeshaThread.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/SandeshaThread.java?rev=581547&r1=581546&r2=581547&view=diff
==============================================================================
--- 
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/SandeshaThread.java
 (original)
+++ 
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/SandeshaThread.java
 Wed Oct  3 02:50:18 2007
@@ -41,6 +41,7 @@
        private boolean hasStoppedRunning = false;
        private boolean hasPausedRunning = false;
        private boolean pauseRequired = false;
+       private boolean stopRequested = false;
        
        private int sleepTime;
   private WorkerLock lock = null;
@@ -88,8 +89,8 @@
                        }
                }
                
-         //we can now request a pause - the next pause will be ours
-         pauseRequired = true;
+               //we can now request a pause - the next pause will be our
+               pauseRequired = true;
                                
                if(hasStoppedRunning() || !isThreadStarted()){
                        throw new 
IllegalStateException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotPauseThread));
@@ -121,6 +122,7 @@
                if (isThreadStarted()) {
                        // the invoker is started so stop it
                        runThread = false;
+                       stopRequested = true;
                        // wait for it to finish
                        while (!hasStoppedRunning()) {
                                try {
@@ -129,12 +131,14 @@
                                        //ignore
                                }
                        }
+                       
+                       stopRequested = false;
                }
                
-           // In a unit test, tracing 'this' once the thread was stopped caused
-           // an exception, so we just trace exit.
-           if (log.isDebugEnabled())
-             log.debug("Exit: SandeshaThread::stopRunning");
+    // In a unit test, tracing 'this' once the thread was stopped caused
+    // an exception, so we just trace exit.
+    if (log.isDebugEnabled())
+      log.debug("Exit: SandeshaThread::stopRunning");
        }
        
        public synchronized boolean isThreadStarted() {
@@ -158,7 +162,7 @@
                SequenceEntry entry = new SequenceEntry(sequenceID, rmSource);
                if (!workingSequences.contains(entry)) 
workingSequences.add(entry);
                
-               if (!isThreadStarted()) {
+               if (!isThreadStarted() && !stopRequested) {
                        if(log.isDebugEnabled()) log.debug("Starting thread");
 
                        this.context = context;
@@ -183,7 +187,9 @@
                                log.error(e);
                                throw new RuntimeException(e);
                        }
-               } else {
+
+                       
+               } else if (!stopRequested){
                        if(log.isDebugEnabled()) log.debug("Waking thread");
                        wakeThread();
                }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to