directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r946511 - /directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
Date Thu, 20 May 2010 02:25:57 GMT
Author: elecharny
Date: Thu May 20 02:25:57 2010
New Revision: 946511

URL: http://svn.apache.org/viewvc?rev=946511&view=rev
Log:
Changed the nbEntries to be an AtomicInteger, removed the synchronization around the getSize()
method.

Modified:
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java?rev=946511&r1=946510&r2=946511&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java Thu May 20 02:25:57
2010
@@ -53,6 +53,7 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.Serializable;
 import java.util.Comparator;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.directory.server.i18n.I18n;
 
@@ -127,7 +128,7 @@ public class BTree<K, V> implements Exte
     protected int pageSize;
 
     /** Total number of entries in the BTree */
-    protected int nbEntries;
+    protected AtomicInteger nbEntries;
 
     /** Serializer used for BPages of this tree */
     private transient BPage<K, V> bpageSerializer;
@@ -185,6 +186,9 @@ public class BTree<K, V> implements Exte
     }
     
     
+    /**
+     * The real BTree constructor.
+     */
     private void createInstance(RecordManager recman, Comparator<?> comparator, Serializer
keySerializer,
         Serializer valueSerializer, int pageSize) throws IOException
     {
@@ -226,6 +230,8 @@ public class BTree<K, V> implements Exte
         this.pageSize = pageSize;
         this.bpageSerializer = new BPage<K, V>();
         this.bpageSerializer.btree = this;
+        this.nbEntries = new AtomicInteger( 0 );
+
         this.recordId = recman.insert( this );
     }
 
@@ -285,7 +291,7 @@ public class BTree<K, V> implements Exte
             rootPage = new BPage<K, V>( this, key, value );
             rootId = rootPage.recid;
             bTreeHeight = 1;
-            nbEntries = 1;
+            nbEntries.set( 1 );
             recordManager.update( recordId, this );
             
             return null;
@@ -311,7 +317,7 @@ public class BTree<K, V> implements Exte
             
             if ( insert.existing == null )
             {
-                nbEntries++;
+                nbEntries.getAndIncrement();
                 dirty = true;
             }
             
@@ -369,7 +375,7 @@ public class BTree<K, V> implements Exte
         
         if ( remove.value != null )
         {
-            nbEntries--;
+            nbEntries.getAndDecrement();
             dirty = true;
         }
         
@@ -513,9 +519,9 @@ public class BTree<K, V> implements Exte
     /**
      * Return the number of entries (size) of the BTree.
      */
-    public synchronized int size()
+    public int size()
     {
-        return nbEntries;
+        return nbEntries.get();
     }
 
 
@@ -557,7 +563,7 @@ public class BTree<K, V> implements Exte
         bTreeHeight = in.readInt();
         rootId = in.readLong();
         pageSize = in.readInt();
-        nbEntries = in.readInt();
+        nbEntries.set( in.readInt() );
     }
 
 
@@ -572,7 +578,7 @@ public class BTree<K, V> implements Exte
         out.writeInt( bTreeHeight );
         out.writeLong( rootId );
         out.writeInt( pageSize );
-        out.writeInt( nbEntries );
+        out.writeInt( nbEntries.get() );
     }
 
 



Mime
View raw message