I've just posted the solution I use as a jira attachment. See http://issues.apache.org/jira/browse/LUCENE-445
It was designed to be used in a multithread environment (tomcat) It contains javadoc to explain the usage. It extends IndexSearcher since that is the object that searches are executed against. So an application module that needs to execute a search does: IndexSearcher searcher=searcherFactory.createSearch(); hits=searcher.search(query); ... handle results searcher.close(); The factory actually returns the same DelayCloseIndexSearcher over and over until it determines the index has changed. It then calls closeWhenDone() and initialises a new instance. (In my application, a separate thread does this, the old instance still gets used until the new one is fully initialised) Feedback would be much appreciated! Thanks, Luc P.s.: finalize() should not be relied on since ther's no way to know when it will be called (if ever). it could be used to detect bugs, but even just adding a finalize() method actually creates some overhead (at least in the sun VM) and may keep objects in memory longer than they would without it. -----Original Message----- From: Olivier Jaquemet [mailto:[EMAIL PROTECTED] Sent: dinsdag 4 oktober 2005 18:39 To: java-user@lucene.apache.org Subject: Re: Renewing IndexSearcher on index change. Volodymyr Bychkoviak wrote: > I'm using following code during program startup [...] > but this method should be used if you are running only one instance of > such program (because one program can unlock index locked by another > program for indexing for example) > Okay this perfect for our application as only one instance can be launched at the same time. thank you very much. In every case I think I will use this to prevent any problem but why nobody uses finalize methods? is it somehow bad to try to close things correctly that way? Olivier --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]