Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@apache.org Received: (qmail 30287 invoked from network); 5 Jul 2002 18:23:00 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 5 Jul 2002 18:23:00 -0000 Received: (qmail 29418 invoked by uid 97); 5 Jul 2002 18:23:10 -0000 Delivered-To: qmlist-jakarta-archive-lucene-user@jakarta.apache.org Received: (qmail 29387 invoked by uid 97); 5 Jul 2002 18:23:10 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 29369 invoked by uid 98); 5 Jul 2002 18:23:09 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: From: Scott Ganyo To: 'Lucene Users List' Subject: RE: IndexReader Pool Date: Fri, 5 Jul 2002 13:22:52 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C22450.F9F51F90" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C22450.F9F51F90 Content-Type: text/plain; charset="iso-8859-1" You are correct. Actually, there have been a few bug fixes since that was posted. Here's a diff to an updated version: @@ -19,11 +19,21 @@ */ public class IndexAccessControl { - public static final Analyzer LUCENE_ANALYZER = new LuceneAnalyzer(); + private static Analyzer s_defaultAnalyzer; private static final Map WRITER_PATHS = new HashMap(); // path -> CheckoutI nfo private static final Map SEARCHER_PATHS = new HashMap(); // path -> Searche r private static final Map OLD_SEARCHERS = new HashMap(); // Searcher -> Chec koutInfo + public static void setDefaultAnalyzer(Analyzer analyzer) + { + s_defaultAnalyzer = analyzer; + } + + public static Analyzer getDefaultAnalyzer() + { + return s_defaultAnalyzer; + } + /** get for adding documents. * blocks: readers until released */ @@ -47,7 +57,7 @@ { try { - info.wait(); // wait for info to be released + synchronized (info) { info.wait(); } // wait for in fo to be released } catch (InterruptedException e) { @@ -61,9 +71,10 @@ { boolean missing = !path.exists(); if (missing) path.mkdir(); - writer = new IndexWriter(path, LUCENE_ANALYZER, /*create*/m issing); + writer = new IndexWriter(path, s_defaultAnalyzer, /*create* /missing); writer.mergeFactor = 2; info = new CheckoutInfo(writer); + WRITER_PATHS.put(path, info); } } while (writer == null); @@ -88,7 +99,7 @@ { WRITER_PATHS.remove(path); writer = info.writer; - info.notify(); // notify waiters to try again + synchronized (info) { info.notify(); } // notify waiters to try again } } } @@ -137,10 +148,12 @@ String sync = path.getAbsolutePath().intern(); synchronized (sync) // sync on specific index { + boolean old = false; CheckoutInfo info = (CheckoutInfo)SEARCHER_PATHS.get(path); if (info == null || searcher != info.searcher) // this isn't the in fo we're looking for { info = (CheckoutInfo)OLD_SEARCHERS.get(searcher); + old = true; } if (info != null) // found a searcher { @@ -148,7 +161,7 @@ { info.checkoutCount--; } - else // last reference to searcher + else if (old)// last reference to old searcher { info.searcher.close(); } @@ -183,7 +196,7 @@ { try { - info.wait(); // wait for info to be released + synchronized (info) { info.wait(); } // wait for in fo to be released } catch (InterruptedException e) { @@ -221,7 +234,7 @@ { WRITER_PATHS.remove(path); reader = info.reader; - info.notify(); // notify waiters to try again + synchronized (info) { info.notify(); } // notify waiters to try again } } } Hope it helps, Scott > -----Original Message----- > From: Ilya Khandamirov [mailto:ikh@startext.de] > Sent: Friday, July 05, 2002 12:13 PM > To: 'Lucene Users List' > Subject: RE: IndexReader Pool > > > Hi P�ter, > > > > http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg0 > 0938.html > > Something wrong with the code or i'm missing something. > WRITER_PATHS is > always empty, i.e. there is no reuse, you always create a new object. > > > Regards, > Ilya > > > -- > To unsubscribe, e-mail: > > For additional commands, e-mail: > > ------_=_NextPart_001_01C22450.F9F51F90--