You can use ReadWriteLock <http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html>as low level technique to manage access.
A ReadWriteLock maintains a pair of associated locks<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/Lock.html>, one for read-only operations and one for writing. The read lock<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html#readLock%28%29>may be held simultaneously by multiple reader threads, so long as there are no writers. The write lock<http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html#writeLock%28%29>is exclusive. 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 <ian....@gmail.com> 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 <paul_t...@fastmail.fm> > 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: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > >