Nikhil (if using reply-all, please remove direct email...) Sounds like you are doing everything correctly. Does your code work correctly with just 1 thread (i.e. just the "main" thread)? Make sure you get that working first. If that works, and N threads does not, then your threads are probably just stepping on each other somewhere.
1 index - 1 IndexWriter. Sharing between threads is OK, just make sure you don't close it in one thread, while something else is using it to write to the index (e.g. use synchronize). Sure, you can close and reopen it. I can't tell what you are doing wrong from the stacktrace, sorry. Otis ----- Original Message ---- From: Nikhil Goel <[EMAIL PROTECTED]> To: java-user@lucene.apache.org; Otis Gospodnetic <[EMAIL PROTECTED]> Sent: Thursday, March 23, 2006 2:04:30 PM Subject: Re: Multiple threads in Lucene Hi Otis, Thanks for the reply but I have one question to ask here. You said big no no for opening opening multiple IndexWriters. I want to clarify :- 1) Do you mean multiple IndexWriters at the same time? I am not doing this. At a time there is only one Indexwriter opened. or 1) Do you mean I cant open another IndexWriter again after closing the prior one. In my writing thread, for every file I index, I open a new IndexWriter and close it and as soon as I have second file available for indexing. I open the IndexWriter again and close it and directory object is the same across all the threads as well as while reopening IndexWriters. If the latter is NO too, then how would a developer make sure that this index is closed when the Program is killed. Suppose a program is killed in between and Index is not closed, then next time when I run the program there will be a write.lock in Index and it won't allow us to open another index. Please let me know if I am wrong in what I said. Thanks -Nikhil On 3/22/06, Otis Gospodnetic <[EMAIL PROTECTED]> wrote: > > Yes, 1 IndexWriter + multiple IndexSearchers definitely work together :) > I can't tell what you're doing wrong with the threads... it looks like you > might be opening multiple IndexWriters on the same index/directory (big no > no). > > Otis > > ----- Original Message ---- > From: Nikhil Goel <[EMAIL PROTECTED]> > To: java-user@lucene.apache.org > Sent: Wednesday, March 22, 2006 6:04:41 PM > Subject: Multiple threads in Lucene > > Hi Lucene Developers, > > According to Lucene Documentation, IndexWriter can exist with multiple > IndexSearcher and its thread safe. To verify that: I wrote a simple > program > to simulate that condition but unfortunately I get an exception. Please > let > me know if anyone has ever tested the Lucene claim that IndexWriter and > IndexSearcher are thread safe. > > > I have a program in which I have 4 threads. > 1) One IndexWriter Thread > 2) 3 IndexSearcher Thread. > > Everytime when we need to index a file. We run the following code in > IndexWriter Thread:- > function IndexFile(Document doc) > { > writer = new IndexWriter(directory, new StandardAnalyzer(), false); > writer.addDocument(doc); > writer.close(); > } > > Our IndexSearcherThread looks like this:- > function IndexSearch(String termToBeSearched) > { > IndexSearchersearcher = new IndexSearcher(directory); > //Note: This directory is the same reference as used to initiate > IndexWriter in Indexfile function. Hence this directory //reference is > used > across all the threads. > > Query query = QueryParser.parse(termToBeSearched, "contents", new > StandardAnalyzer()); > Hits hits = searcher.search(query); > } > > If I execute these 4 threads above together, then whenever a search > routine > gets executed and IndexWriter is also in use, then I get an error at the > following line:- writer.close(); > > Stack Strace looks like this:- > unable to close the writer stream > java.io.IOException: read past EOF > at org.apache.lucene.store.InputStream.refill(InputStream.java:192) > at org.apache.lucene.store.InputStream.readByte(InputStream.java:81) > at org.apache.lucene.store.InputStream.readBytes(InputStream.java:95) > at org.apache.lucene.index.SegmentReader.norms(SegmentReader.java:375) > at org.apache.lucene.index.SegmentReader.norms(SegmentReader.java:342) > at org.apache.lucene.index.SegmentMerger.mergeNorms(SegmentMerger.java > :306) > at org.apache.lucene.index.SegmentMerger.merge(SegmentMerger.java:99) > at org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java > :430) > at org.apache.lucene.index.IndexWriter.flushRamSegments( > IndexWriter.java > :383) > at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:193) > > > Thanks in advance > -Nikhil > > > > > --------------------------------------------------------------------- > 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]