From 71a4cadf31f95610cfaf49e28bfe8d4072740d19 Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 5 May 2009 20:19:51 +0000 Subject: [PATCH] better and more performant synchronization in SimpleARC, the caching object for word hashes. Speeds up indexing. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5925 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/kelondro/index/SimpleARC.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source/de/anomic/kelondro/index/SimpleARC.java b/source/de/anomic/kelondro/index/SimpleARC.java index 38dcab90f..313ee9d4d 100644 --- a/source/de/anomic/kelondro/index/SimpleARC.java +++ b/source/de/anomic/kelondro/index/SimpleARC.java @@ -24,6 +24,7 @@ package de.anomic.kelondro.index; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -40,22 +41,22 @@ public class SimpleARC { public final static boolean accessOrder = false; // if false, then a insertion-order is used private int cacheSize; - private LinkedHashMap levelA, levelB; + private Map levelA, levelB; public SimpleARC(int cacheSize) { this.cacheSize = cacheSize / 2; - this.levelA = new LinkedHashMap(cacheSize, 0.1f, accessOrder) { + this.levelA = Collections.synchronizedMap(new LinkedHashMap(cacheSize, 0.1f, accessOrder) { private static final long serialVersionUID = 1L; @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > SimpleARC.this.cacheSize; } - }; - this.levelB = new LinkedHashMap(cacheSize, 0.1f, accessOrder) { + }); + this.levelB = Collections.synchronizedMap(new LinkedHashMap(cacheSize, 0.1f, accessOrder) { private static final long serialVersionUID = 1L; @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > SimpleARC.this.cacheSize; } - }; + }); } /** @@ -64,7 +65,7 @@ public class SimpleARC { * @param s * @param v */ - public synchronized void put(K s, V v) { + public void put(K s, V v) { assert this.levelA.get(s) == null; assert this.levelB.get(s) == null; this.levelA.put(s, v); @@ -76,7 +77,7 @@ public class SimpleARC { * @param s * @return the value */ - public synchronized V get(K s) { + public V get(K s) { V v = this.levelB.get(s); if (v != null) return v; v = this.levelA.remove(s); @@ -91,7 +92,7 @@ public class SimpleARC { /** * clear the cache */ - public synchronized void clear() { + public void clear() { this.levelA.clear(); this.levelB.clear(); }