diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java
index 6e506422cef6124957242c1b043b6ed08ebdfd78..e511511c51aa6a7e7c0bd376cf0a25713733831f 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigRestartBean.java
@@ -111,13 +111,17 @@ public class ConfigRestartBean {
     }
 
     private static boolean isShuttingDown(RouterContext ctx) {
-        return Router.EXIT_GRACEFUL == ctx.router().scheduledGracefulExitCode() ||
-               Router.EXIT_HARD == ctx.router().scheduledGracefulExitCode();
+        int code = ctx.router().scheduledGracefulExitCode();
+        return Router.EXIT_GRACEFUL == code ||
+               Router.EXIT_HARD == code;
     }
+
     private static boolean isRestarting(RouterContext ctx) {
-        return Router.EXIT_GRACEFUL_RESTART == ctx.router().scheduledGracefulExitCode() ||
-               Router.EXIT_HARD_RESTART == ctx.router().scheduledGracefulExitCode();
+        int code = ctx.router().scheduledGracefulExitCode();
+        return Router.EXIT_GRACEFUL_RESTART == code ||
+               Router.EXIT_HARD_RESTART == code;
     }
+
     /** this is for summaryframe.jsp */
     public static long getRestartTimeRemaining() {
         RouterContext ctx = ContextHelper.getContext(null);
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index e80c91237e9a82982c4e1ad0bdcc8f119e8c6519..26271f10c021ac90b4f7815734aae46344ada44c 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -1361,8 +1361,8 @@ public class Router implements RouterClock.ClockShiftListener {
             if (isFinalShutdownInProgress())
                 return; // too late
             changeState(State.GRACEFUL_SHUTDOWN);
+            _gracefulExitCode = exitCode;
         }
-        _gracefulExitCode = exitCode;
         //_config.put(PROP_SHUTDOWN_IN_PROGRESS, "true");
         _context.throttle().setShutdownStatus();
         synchronized (_gracefulShutdownDetector) {
@@ -1380,8 +1380,8 @@ public class Router implements RouterClock.ClockShiftListener {
             if (isFinalShutdownInProgress())
                 return; // too late
             changeState(State.RUNNING);
+            _gracefulExitCode = -1;
         }
-        _gracefulExitCode = -1;
         //_config.remove(PROP_SHUTDOWN_IN_PROGRESS);
         _context.throttle().cancelShutdownStatus();
         synchronized (_gracefulShutdownDetector) {
@@ -1394,16 +1394,22 @@ public class Router implements RouterClock.ClockShiftListener {
      *
      * @return one of the EXIT_* values or -1
      */
-    public int scheduledGracefulExitCode() { return _gracefulExitCode; }
+    public int scheduledGracefulExitCode() {
+        synchronized(_stateLock) {
+            return _gracefulExitCode;
+        }
+    }
 
     /**
      *  How long until the graceful shutdown will kill us?
      *  @return -1 if no shutdown in progress.
      */
     public long getShutdownTimeRemaining() {
-        if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better?
-        if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART)
-            return 0;
+        synchronized(_stateLock) {
+            if (_gracefulExitCode <= 0) return -1; // maybe Long.MAX_VALUE would be better?
+            if (_gracefulExitCode == EXIT_HARD || _gracefulExitCode == EXIT_HARD_RESTART)
+                return 0;
+        }
         long exp = _context.tunnelManager().getLastParticipatingExpiration();
         if (exp < 0)
             return 0;