You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2012/04/17 21:57:51 UTC

svn commit: r1327254 - /ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java

Author: doogie
Date: Tue Apr 17 19:57:50 2012
New Revision: 1327254

URL: http://svn.apache.org/viewvc?rev=1327254&view=rev
Log:
FIX: Fix race condition in startup code; it's possible for all loaders to be
started, a shutdown command get's issued, stopping is occurring, but
then the server state ends up being set to RUNNING.

Modified:
    ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java

Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java?rev=1327254&r1=1327253&r2=1327254&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java (original)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Tue Apr 17 19:57:50 2012
@@ -272,8 +272,15 @@ public class Start {
     }
 
     private void shutdownServer() {
-        if (this.serverState.get() == ServerState.STOPPING) return;
-        this.serverState.set(ServerState.STOPPING);
+        ServerState currentState;
+        do {
+            currentState = this.serverState.get();
+            if (currentState == ServerState.STOPPING) {
+                return;
+            }
+        } while (!this.serverState.compareAndSet(currentState, ServerState.STOPPING));
+        // The current thread was the one that successfully changed the state;
+        // continue with further processing.
         synchronized (this.loaders) {
             // Unload in reverse order
             for (int i = this.loaders.size(); i > 0; i--) {
@@ -318,9 +325,8 @@ public class Start {
                     return false;
                 }
             }
-            this.serverState.set(ServerState.RUNNING);
         }
-        return true;
+        return this.serverState.compareAndSet(ServerState.STARTING, ServerState.RUNNING);
     }
 
     public String status() throws IOException {