Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 30415 invoked from network); 19 Aug 2004 11:22:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Aug 2004 11:22:21 -0000 Received: (qmail 7167 invoked by uid 500); 19 Aug 2004 11:22:11 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 7132 invoked by uid 500); 19 Aug 2004 11:22:11 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 7108 invoked by uid 99); 19 Aug 2004 11:22:10 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=DNS_FROM_RFC_ABUSE X-Spam-Check-By: apache.org Received: from [216.136.173.245] (HELO web12708.mail.yahoo.com) (216.136.173.245) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 19 Aug 2004 04:22:08 -0700 Message-ID: <20040819112207.70508.qmail@web12708.mail.yahoo.com> Received: from [195.29.107.48] by web12708.mail.yahoo.com via HTTP; Thu, 19 Aug 2004 04:22:07 PDT Date: Thu, 19 Aug 2004 04:22:07 -0700 (PDT) From: Otis Gospodnetic Subject: RE: Re: OutOfMemoryError To: Lucene Users List , Terence Lai In-Reply-To: <1568841828141956321EDOKUHORGE.tlai@trekspace.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Terence, > 2) I have a background process to update the index files. If I keep > the IndexSearcher opened, I am not sure whether it will pick up the > changes from the index updates done in the background process. This is a frequently asked question. Basically, you have to make use of IndexReader's method for checking the index version. You can do it as often as you want, it's really up to you, and when you detect that the index has been modified, throw away the old IndexSearcher and make a new one. If you are sure nobody is using your old IndexSearcher, you can close() it, but if somebody (e.g. another thread) is still using it and you close() it, you will get an error. Otis > > Reuse your IndexSearcher! :) > > > > Also, I think somebody has written some EJB stuff to work with > Lucene. > > The project is on SF.net. > > > > Otis > > > > --- Terence Lai wrote: > > > > > Hi All, > > > > > > I am getting a OutOfMemoryError when I deploy my EJB application. > To > > > debug the problem, I wrote the following test program: > > > > > > public static void main(String[] args) { > > > try { > > > Query query = getQuery(); > > > > > > for (int i=0; i<1000; i++) { > > > search(query); > > > > > > if ( i%50 == 0 ) { > > > System.out.println("Sleep..."); > > > Thread.currentThread().sleep(5000); > > > System.out.println("Wake up!"); > > > } > > > } > > > } catch (Exception e) { > > > e.printStackTrace(); > > > } > > > } > > > > > > private static void search(Query query) throws IOException { > > > FSDirectory fsDir = null; > > > IndexSearcher is = null; > > > Hits hits = null; > > > > > > try { > > > fsDir = FSDirectory.getDirectory("C:\\index, false); > > > is = new IndexSearcher(fsDir); > > > SortField sortField = new > > > SortField("profile_modify_date", > > > SortField.STRING, true); > > > > > > hits = is.search(query, new Sort(sortField)); > > > } finally { > > > if (is != null) { > > > try { > > > is.close(); > > > } catch (Exception ex) { > > > } > > > } > > > > > > if (fsDir != null) { > > > try { > > > is.close(); > > > } catch (Exception ex) { > > > } > > > } > > > } > > > > > > } > > > > > > In the test program, I wrote a loop to keep calling the search > > > method. Everytime it enters the search method, I would > instantiate > > > the IndexSearcher. Before I exit the method, I close the > > > IndexSearcher and FSDirectory. I also made the Thread sleep for 5 > > > seconds in every 50 searches. Hopefully, this will give some time > for > > > the java to do the Garbage Collection. Unfortunately, when I > observe > > > the memory usage of my process, it keeps increasing until I got > the > > > java.lang.OutOfMemoryError. > > > > > > Note that I invoke the IndexSearcher.search(Query query, Sort > sort) > > > to process the search. If I don't specify the Sort field(i.e. > using > > > IndexSearcher.search(query)), I don't have this problem, and the > > > memory usage keeps at a very static level. > > > > > > Does anyone experience a similar problem? Did I do something > wrong in > > > the test program. I throught by closing the IndexSearcher and the > > > FSDirectory, the memory will be able to release during the > Garbage > > > Collection. > > > > > > Thanks, > > > Terence > > > > > > > > > > > > > > > ---------------------------------------------------------- > > > Get your free email account from http://www.trekspace.com > > > Your Internet Virtual Desktop! > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: > lucene-user-unsubscribe@jakarta.apache.org > > > For additional commands, e-mail: > lucene-user-help@jakarta.apache.org > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org > > For additional commands, e-mail: > lucene-user-help@jakarta.apache.org > > > > > > > ---------------------------------------------------------- > Get your free email account from http://www.trekspace.com > Your Internet Virtual Desktop! > > --------------------------------------------------------------------- > To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: lucene-user-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org