From 2e31d586873aca4a32b71ee780c71b92bcf07f28 Mon Sep 17 00:00:00 2001 From: gojomo Date: Fri, 23 Oct 2009 22:33:36 +0000 Subject: [PATCH] * ObjectIdentityBdbCache.java replace costly bdb size() operation with maintained counter --- .../main/java/org/archive/util/ObjectIdentityBdbCache.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commons/src/main/java/org/archive/util/ObjectIdentityBdbCache.java b/commons/src/main/java/org/archive/util/ObjectIdentityBdbCache.java index 5ed56d48..771af365 100644 --- a/commons/src/main/java/org/archive/util/ObjectIdentityBdbCache.java +++ b/commons/src/main/java/org/archive/util/ObjectIdentityBdbCache.java @@ -88,6 +88,8 @@ implements ObjectIdentityCache, Closeable, Serializable { /** The Collection view of the BDB JE database used for this instance. */ protected transient StoredSortedMap diskMap; + protected AtomicLong count; + // // USAGE STATS // @@ -162,6 +164,7 @@ implements ObjectIdentityCache, Closeable, Serializable { this.db = openDatabase(env, dbName); this.diskMap = createDiskMap(this.db, classCatalog, valueClass); + this.count = new AtomicLong(diskMap.size()); } @SuppressWarnings("unchecked") @@ -271,6 +274,7 @@ implements ObjectIdentityCache, Closeable, Serializable { // (rather than just the memMap until page-out) // ensures diskMap.keySet() provides complete view V prevVal = diskMap.putIfAbsent(key, valDisk); + count.incrementAndGet(); if(prevVal!=null) { // ERROR: diskMap modification since previous // diskMap.get() should be impossible @@ -343,7 +347,7 @@ implements ObjectIdentityCache, Closeable, Serializable { if(db==null) { return 0; } - return diskMap.size(); + return (int) count.get(); } protected String getDatabaseName() {