lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaoxianyang <>
Subject IndexSearcher close() and search() called concurrently by different threads?
Date Tue, 29 Sep 2009 17:50:09 GMT


I am new to Lucene.  Hope the question is not too naive.

>From Lucene FAQ, i know that IndexSearcher instance shall be shared by
threads, rather than opening one for each thread.  However, after index
rebuild, we need to create a new IndexSearcher instance, and call close() on
the old indexSearcher instance.   Here is the pseudo code:

public class SearchEngine {

  private IndexSearcher iSearcher = null;

  public void setIndexSearcher(IndexSearcher searcher) {
          this.iSearcher = searcher;

  public void search() {

     iSearcher search();


As you can see, after index rebuild, one thread wants to call
SearchEngine.setIndexSearcher to instantiate a new IndexSearcher.  Before
that, it also needs to clean up the resource of the old IndexSearcher by
calling close().    At the same time, another thread is in the middle of
search of the old indexSearcher object.  

That is why I am concerned whether I might get some weird exception by
calling searcher.close() and concurrently by different
threads.   Will that be a problem?  Or lucene takes care of the
synchronization between close() and search(), or that does not need any
synchronization at all?  Bottom line is that I don't want to do
synchronization between close() and search().

Or is there more elegant way of passing a new IndexSearcher after index
rebuild without any resource leak?

View this message in context:
Sent from the Lucene - General mailing list archive at

View raw message