commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1035550 - /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java
Date Tue, 16 Nov 2010 08:05:24 GMT
Author: rgoers
Date: Tue Nov 16 08:05:24 2010
New Revision: 1035550

URL: http://svn.apache.org/viewvc?rev=1035550&view=rev
Log:
Use ConcurrentMap instead of synchronization

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java?rev=1035550&r1=1035549&r2=1035550&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java
Tue Nov 16 08:05:24 2010
@@ -22,6 +22,8 @@ import org.apache.commons.vfs2.FileSyste
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * A {@link org.apache.commons.vfs2.FilesCache} implementation.<br>
@@ -35,8 +37,8 @@ public class DefaultFilesCache extends A
 {
 
     /** The FileSystem cache */
-    private final Map<FileSystem, Map<FileName, FileObject>> filesystemCache
=
-          new HashMap<FileSystem, Map<FileName, FileObject>>(10);
+    private final ConcurrentMap<FileSystem, ConcurrentMap<FileName, FileObject>>
filesystemCache =
+          new ConcurrentHashMap<FileSystem, ConcurrentMap<FileName, FileObject>>(10);
 
     public void putFile(final FileObject file)
     {
@@ -56,13 +58,13 @@ public class DefaultFilesCache extends A
         files.clear();
     }
 
-    protected Map<FileName, FileObject> getOrCreateFilesystemCache(FileSystem filesystem)
+    protected ConcurrentMap<FileName, FileObject> getOrCreateFilesystemCache(FileSystem
filesystem)
     {
-        Map<FileName, FileObject> files = filesystemCache.get(filesystem);
+        ConcurrentMap<FileName, FileObject> files = filesystemCache.get(filesystem);
         if (files == null)
         {
-            files = new HashMap<FileName, FileObject>();
-            filesystemCache.put(filesystem, files);
+            filesystemCache.putIfAbsent(filesystem, new ConcurrentHashMap<FileName, FileObject>());
+            files = filesystemCache.get(filesystem);
         }
 
         return files;



Mime
View raw message