On 22 November 2010 23:23, <rgo...@apache.org> wrote: > 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);
Could be made final. > > 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; > } > } > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org