[jboss-cvs] JBossAS SVN: r87388 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 15 16:41:26 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-04-15 16:41:26 -0400 (Wed, 15 Apr 2009)
New Revision: 87388

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
Log:
Small performance enhancement: using a volatile int saves a few million calls to AtomicInteger.get() (saves around 200ms in startup by my crappy measurements)

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-04-15 19:47:38 UTC (rev 87387)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-04-15 20:41:26 UTC (rev 87388)
@@ -32,7 +32,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFSUtils;
@@ -103,8 +103,11 @@
    private transient String localVfsPath;
 
    /** The reference count */
-   private transient AtomicInteger references = new AtomicInteger(0);
+   private transient volatile int references;
 
+   /** The reference count updater */
+   private static final AtomicIntegerFieldUpdater<AbstractVirtualFileHandler> referencesUpdater = AtomicIntegerFieldUpdater.newUpdater(AbstractVirtualFileHandler.class, "references");
+
    /** The cached last modified */
    protected transient long cachedLastModified;
 
@@ -538,7 +541,7 @@
     */
    protected int increment()
    {
-      return references.incrementAndGet();
+      return referencesUpdater.incrementAndGet(this);
    }
 
    /**
@@ -548,7 +551,7 @@
     */
    protected int decrement()
    {
-      return references.decrementAndGet();
+      return referencesUpdater.decrementAndGet(this);
    }
 
    /**
@@ -558,7 +561,7 @@
     */
    protected void checkClosed() throws IllegalStateException 
    {
-      if (references.get() < 0)
+      if (references < 0)
          throw new IllegalStateException("Closed " + toStringLocal());
    }
 
@@ -569,7 +572,7 @@
     */
    protected int getReferences()
    {
-      return references.get();
+      return references;
    }
 
    public void cleanup()
@@ -596,7 +599,7 @@
       }
       finally
       {
-         references.decrementAndGet();   
+         referencesUpdater.decrementAndGet(this);
       }
    }
 
@@ -833,7 +836,7 @@
       this.name = (String) fields.get("name", null);
       VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
       this.context = factory.getVFS(rootURI);
-      this.references = new AtomicInteger(0);
+      this.references = 0;
       this.vfsUrl = (URL)fields.get("vfsUrl", null);
    }
 }




More information about the jboss-cvs-commits mailing list