lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Elschot <>
Subject Possible thread safety problem in CachingWrapperFilter
Date Tue, 04 Sep 2007 18:22:19 GMT

I'm trying to change the CachingWrapperFilter class to cache a
SortedVIntList for LUCENE-584. That is progressing nicely, but
I found this snippet at the beginning of the current
CachingWrapperFilter.bits() method:

    if (cache == null) {
      cache = new WeakHashMap();

I think the initial snippet is not thread safe and might result
in two threads initializing this cache to different objects,
possibly conflicting with the cache accesses after that:

synchronized (cache) { ... cache.get(...); } 
synchronized (cache) { cache.put(...); } 

Would this be safe to initialize the cache:

synchronized(this) {
    if (cache == null) {
      cache = new WeakHashMap();

and should the cache accesses also use synchronized(this) ?

Paul Elschot

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message