Author: sshafroi
Date: 2008-08-04 16:10:26 +0200 (Mon, 04 Aug 2008)
New Revision: 6755
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
Log:
I removed the read lock in r6754, thinking it was OK. Which is of course isn't.
I will blame last day before holiday, and a thanks to tipsy Mick for spotting
it.
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
===================================================================
---
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
2008-07-25 12:14:35 UTC (rev 6754)
+++
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
2008-08-04 14:10:26 UTC (rev 6755)
@@ -24,7 +24,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.HashMap;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
@@ -90,11 +89,22 @@
private static WeakHashMap<Class<? extends Visitor>,
ConcurrentHashMap<Class<? extends Clause>, Method>> cache =
new WeakHashMap<Class<? extends Visitor>, ConcurrentHashMap<Class<?
extends Clause>, Method>>();
private static ReadWriteLock cacheLock = new ReentrantReadWriteLock();
+ private static Lock readLock = cacheLock.readLock();
+ private static Lock writeLock = cacheLock.writeLock();
+
public void visit(final Clause clause) {
- ConcurrentHashMap<Class<? extends Clause>, Method> map =
cache.get(getClass());
+ ConcurrentHashMap<Class<? extends Clause>, Method> map;
+ try {
+ readLock.lock();
+ map = cache.get(getClass());
+ }
+ finally {
+ readLock.unlock();
+ }
+
if (map == null) {
- try{
- cacheLock.writeLock().lock();
+ try {
+ writeLock.lock();
map = cache.get(getClass());
if (map == null) {
map = new ConcurrentHashMap<Class<? extends Clause>,
Method>();
@@ -102,7 +112,7 @@
}
}
finally {
- cacheLock.writeLock().unlock();
+ writeLock.unlock();
}
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits