commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1037935 - /commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
Date Mon, 22 Nov 2010 23:23:59 GMT
Author: rgoers
Date: Mon Nov 22 23:23:59 2010
New Revision: 1037935

URL: http://svn.apache.org/viewvc?rev=1037935&view=rev
Log:
Fox for VFS-343. Use AtomicInteger instead of synchronizing on FileSystem

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java?rev=1037935&r1=1037934&r2=1037935&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
Mon Nov 22 23:23:59 2010
@@ -46,6 +46,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * A partial {@link org.apache.commons.vfs2.FileSystem} implementation.
@@ -101,7 +102,7 @@ public abstract class AbstractFileSystem
     /**
      * open streams counter for this filesystem
      */
-    private int openStreams;
+    private AtomicInteger openStreams = new AtomicInteger(0);
 
     protected AbstractFileSystem(final FileName rootName,
                                  final FileObject parentLayer,
@@ -647,24 +648,25 @@ public abstract class AbstractFileSystem
 
     void streamOpened()
     {
-        synchronized (this)
-        {
-            openStreams++;
-        }
+        openStreams.incrementAndGet();
     }
 
     void streamClosed()
     {
-        synchronized (this)
+        int count;
+
+        do
         {
-            if (openStreams > 0)
+            count = openStreams.get();
+            if (count < 1)
             {
-                openStreams--;
-                if (openStreams < 1)
-                {
-                    notifyAllStreamsClosed();
-                }
+                return;
             }
+        } while(openStreams.compareAndSet(count, count - 1));
+
+        if (count == 1)
+        {
+            notifyAllStreamsClosed();
         }
     }
 
@@ -681,9 +683,6 @@ public abstract class AbstractFileSystem
      */
     public boolean isOpen()
     {
-        synchronized (this)
-        {
-            return openStreams > 0;
-        }
+        return openStreams.get() > 0;
     }
 }



Mime
View raw message