lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Terence Lai <t...@trekspace.com>
Subject RE: Re: OutOfMemoryError
Date Wed, 18 Aug 2004 20:42:53 GMT
Hi,

I tried to reuse the IndexSearcher, but I have another question. What happen if an application
server unloads the class after it is idle for a while, and then re-instantiate the object
back when it recieves a new request?

Everytime the server re-instantiates the class, a new IndexSearcher instance will be created.
If the IndexSearcher.close() method does not release all the memory and the server keeps unloading
and re-instantiating the class, it will eventually hit the OutOfMemoryError issue. The test
program from my previous email is simulating this condition. The reason why I instantiate/close
the IndexSearcher inside the loop is to simulate the scenario when the server unloads and
re-instantiates the object. I think that the same issue will happen if the application is
written in servlet.

Although the singleton pattern may resolve the problem that I described above; however, it
isn't permitted by the J2EE spec according to some news letters. In order words, I can't use
singleton pattern in EJB. Please correct me if I am wrong on this.

Thanks,
Terence

> 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 <tlai@trekspace.com> 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


Mime
View raw message