lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Umesh Prasad <>
Subject Re: Closing indexsearcher , making sur eit is in use
Date Fri, 14 Jan 2011 06:59:00 GMT
You can use  ReadWriteLock
low level technique to manage access.

A ReadWriteLock maintains a pair of associated
one for read-only operations and one for writing. The read
be held simultaneously by multiple reader threads, so long as there
no writers. The write

Wrap the lucene's searcher into your SearchManager class, which exposes its
own API for search and forwards the requests to underlying searcher.

 The search and reopen will sync up by using ReadWriteLock . search takes
readlock and reopen takes writelock.

PS: 1. Use indexreader.reopen() instead of closing it off and then open
again. It is much faster. (Documented)
Thanks & Regards
Umesh Prasad

On Fri, Jan 14, 2011 at 2:25 AM, Ian Lea <> wrote:

> Use something with reference counting - Lucene in action second
> edition has a searcher manager class  which I think might be available
> standalone.  Or a couple of low-tech alternatives: instead of closing
> the old searcher, move it out of the way and keep a reference to it
> and close it after n seconds or searches or whatever.  Or catch the
> closed Exception and rerun the query with the up to date searcher.
> --
> Ian.
> On Thu, Jan 13, 2011 at 8:21 PM, Paul Taylor <>
> wrote:
> > As recommended, I use just one Index Searcher on my multithreaded GUI app
> > using a singleton pattern
> > If data is modified in the index I then close the reader and searcher,
> and
> > they will be recreate on next call to getInstance() but Ive hit a problem
> > whereby one thread was closing a searcher, another thread already the
> > searcher open but when came to use it gave exception 'the IndexReader is
> > closed'
> >
> > I obviously dont want access to the searcher to be synchronized as it is
> > designed to work multithreaded, so how should I close it safetly, i.e
> close
> > if no current references to it.
> >
> > Paul
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message