src/java.base/share/classes/java/net/ServerSocket.java
changeset 52456 90ff0e286a5e
parent 52427 3c6aa484536c
child 52499 768b1c612100
--- a/src/java.base/share/classes/java/net/ServerSocket.java	Thu Nov 08 10:36:06 2018 -0500
+++ b/src/java.base/share/classes/java/net/ServerSocket.java	Thu Nov 08 16:16:57 2018 +0000
@@ -993,8 +993,8 @@
         return getImpl().getOption(name);
     }
 
-    private static Set<SocketOption<?>> options;
-    private static boolean optionsSet = false;
+    // cache of unmodifiable impl options. Possibly set racy, in impl we trust
+    private volatile Set<SocketOption<?>> options;
 
     /**
      * Returns a set of the socket options supported by this server socket.
@@ -1008,19 +1008,17 @@
      * @since 9
      */
     public Set<SocketOption<?>> supportedOptions() {
-        synchronized (ServerSocket.class) {
-            if (optionsSet) {
-                return options;
-            }
-            try {
-                SocketImpl impl = getImpl();
-                options = Collections.unmodifiableSet(impl.supportedOptions());
-            } catch (IOException e) {
-                options = Collections.emptySet();
-            }
-            optionsSet = true;
-            return options;
+        Set<SocketOption<?>> so = options;
+        if (so != null)
+            return so;
+
+        try {
+            SocketImpl impl = getImpl();
+            options = Collections.unmodifiableSet(impl.supportedOptions());
+        } catch (IOException e) {
+            options = Collections.emptySet();
         }
+        return options;
     }
 
     static {