CURATOR-460 Make startOfSuspendedEpoch volatile

Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/5920c744
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/5920c744
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/5920c744

Branch: refs/heads/master
Commit: 5920c744508afd678a20309313e1b8d78baac0c4
Parents: b6af8fd
Author: javando <antonio.rafael...@gmail.com>
Authored: Fri Apr 6 00:39:21 2018 -0300
Committer: javando <antonio.rafael...@gmail.com>
Committed: Fri Apr 6 00:39:21 2018 -0300

----------------------------------------------------------------------
 .../framework/state/ConnectionStateManager.java    | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5920c744/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
 
b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
index b66ca7e..b9384d2 100644
--- 
a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
+++ 
b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
@@ -75,8 +75,8 @@ public class ConnectionStateManager implements Closeable
 
     // guarded by sync
     private ConnectionState currentConnectionState;
-    // guarded by sync
-    private long startOfSuspendedEpoch = 0;
+
+    private volatile long startOfSuspendedEpoch = 0;
 
     private enum State
     {
@@ -251,15 +251,8 @@ public class ConnectionStateManager implements Closeable
         {
             try
             {
-
-                int useSessionTimeoutMs;
-                long elapsedMs;
-
-                synchronized (this) {
-                    useSessionTimeoutMs = getUseSessionTimeoutMs();
-                    elapsedMs = this.startOfSuspendedEpoch == 0 ? 
useSessionTimeoutMs / 2 : System.currentTimeMillis() - 
this.startOfSuspendedEpoch;
-                }
-
+                int useSessionTimeoutMs = getUseSessionTimeoutMs();
+                long elapsedMs = startOfSuspendedEpoch == 0 ? 
useSessionTimeoutMs / 2 : System.currentTimeMillis() - startOfSuspendedEpoch;
                 long pollMaxMs = useSessionTimeoutMs - elapsedMs;
 
                 final ConnectionState newState = eventQueue.poll(pollMaxMs, 
TimeUnit.MILLISECONDS);
@@ -339,7 +332,7 @@ public class ConnectionStateManager implements Closeable
         startOfSuspendedEpoch = (currentConnectionState == 
ConnectionState.SUSPENDED) ? System.currentTimeMillis() : 0;
     }
 
-    private synchronized int getUseSessionTimeoutMs() {
+    private int getUseSessionTimeoutMs() {
         int lastNegotiatedSessionTimeoutMs = 
client.getZookeeperClient().getLastNegotiatedSessionTimeoutMs();
         int useSessionTimeoutMs = (lastNegotiatedSessionTimeoutMs > 0) ? 
lastNegotiatedSessionTimeoutMs : sessionTimeoutMs;
         useSessionTimeoutMs = sessionExpirationPercent > 0 && 
startOfSuspendedEpoch != 0 ? (useSessionTimeoutMs * sessionExpirationPercent) / 
100 : useSessionTimeoutMs;

Reply via email to