what is GB?
On Tue, Sep 29, 2009 at 2:41 PM, Diego Cassinera <[email protected]> wrote: > If you close the indexSearcher while a thread is using it, the thread will > eventually throw a ioexception. One suggestion is to create a getSearcher > function that returns iSearcher, which is used by a thread to obtain the > searcher used during the processing of a query. The function > setIndexSearcher should not close the searcher (GB will take care of it), > instead sets iSearcher to new searcher. This way threads that are using the > old searcher can continue using it. Eventually all thread will be using the > new searcher, thus GB will clean up the old searcher. > > -----Mensaje original----- > De: shaoxianyang [mailto:[email protected]] > Enviado el: Tuesday, September 29, 2009 2:50 PM > Para: [email protected] > Asunto: IndexSearcher close() and search() called concurrently by different > threads? > > > Hi, > > 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.close(); > 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 searcher.search() 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: > http://www.nabble.com/IndexSearcher-close%28%29-and-search%28%29-called-conc > urrently-by-different-threads--tp25667782p25667782.html > Sent from the Lucene - General mailing list archive at Nabble.com. >
