< prev index next >

src/share/classes/java/net/URLConnection.java

Print this page

        

@@ -283,16 +283,11 @@
     private MessageHeader requests;
 
    /**
     * @since   JDK1.1
     */
-    private static FileNameMap fileNameMap;
-
-    /**
-     * @since 1.2.2
-     */
-    private static boolean fileNameMapLoaded = false;
+    private static volatile FileNameMap fileNameMap;
 
     /**
      * Loads filename map (a mimetable) from a data file. It will
      * first try to load the user-specific table, defined
      * by &quot;content.types.user.table&quot; property. If that fails,

@@ -300,24 +295,27 @@
      *
      * @return the FileNameMap
      * @since 1.2
      * @see #setFileNameMap(java.net.FileNameMap)
      */
-    public static synchronized FileNameMap getFileNameMap() {
-        if ((fileNameMap == null) && !fileNameMapLoaded) {
-            fileNameMap = sun.net.www.MimeTable.loadTable();
-            fileNameMapLoaded = true;
-        }
+    public static FileNameMap getFileNameMap() {
+        FileNameMap map = fileNameMap;
+
+        if (map == null) {
+            fileNameMap = map = new FileNameMap() {
+                private FileNameMap internalMap =
+                    sun.net.www.MimeTable.loadTable();
 
-        return new FileNameMap() {
-            private FileNameMap map = fileNameMap;
             public String getContentTypeFor(String fileName) {
-                return map.getContentTypeFor(fileName);
+                    return internalMap.getContentTypeFor(fileName);
             }
         };
     }
 
+        return map;
+    }
+
     /**
      * Sets the FileNameMap.
      * <p>
      * If there is a security manager, this method first calls
      * the security manager's {@code checkSetFactory} method
< prev index next >