lucene-lucene-net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Digy" <digyd...@gmail.com>
Subject RE: thread safety
Date Fri, 02 Apr 2010 23:00:14 GMT
A sample app. may be as below. (in Lucene.Net 2.9.x)

 

IndexWriter singletonIndexWriter;

 

void IndexerThread()

{

       while(true)

       {

             //......

             singletonIndexWriter.AddDocument(....);

             if(needed) singletonIndexWriter.Commit();

       }

}

 

//Called by different threads. No "lock" is needed!

void Search()

{

       IndexSearcher src = new IndexSearcher(
singletonIndexWriter.GetReader() );

       //search

       src.Close();

}

 

 

DIGY

 

-----Original Message-----
From: emagdnim paradox [mailto:bwsithspawn00@yahoo.com] 
Sent: Saturday, April 03, 2010 1:10 AM
To: lucene-net-user@lucene.apache.org
Subject: Re: thread safety

 

So is the problem something like:

 

if (!reader.IsCurrent) {

//Other thread closes reader

reader.ReOpen(); //fails because reader is now closed

}

 

? 

 

Does IndexSearcher do this automatically, or can I just know that when I
refresh the reader I need to lock it first? Or are you saying that there are
additional difficulties with using indexsearcher?

 

 

 

 

----- Original Message ----

From: Franklin Simmons <fsimmons@sccmediaserver.com>

To: "lucene-net-user@lucene.apache.org" <lucene-net-user@lucene.apache.org>

Sent: Fri, April 2, 2010 3:24:41 PM

Subject: RE: thread safety

 

You will run into trouble using a singleton IndexSearcher.  Use a singleton
IndexReader, and create IndexSearcher's on demand.  

 

You would need to synchronize the singleton IndexReader for a dynamic index
employing IndexReader.IsCurrent / IndexReader.ReOpen to keep search results
up to date.

 

-----Original Message-----

From: emagdnim paradox [mailto:bwsithspawn00@yahoo.com] 

Sent: Friday, April 02, 2010 1:54 PM

To: lucene-net-user@lucene.apache.org

Subject: thread safety

 

Hey,

 

I'm having difficulty understanding what pieces of lucene are thread safe.
The index searcher documentation, for example, says "Instance members are
not guaranteed to be  thread-safe."

 

If I have a singleton index searcher that my whole process can access, can
the threads access it without locking? Are there any examples of using
lucene.net in a multi-threaded app I could look at?

 

Thanks,

-Ben

 

 

      


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message