I am googling for two days… I really need help.
I have an application with multiple threads trying to update a lucene index using Open/Close of IndexWriter for each update. Threads can start at any time.
Yeah, the problem with write.lock! So there are may be two or more solutions:
1) check IndexWriter.IsLocked(index) and if it is locked to sleep the thread.
2) Open an IndexWriter and never close it. The problem is that I have another application using the same index. Also when should I close the index and finalize the whole process?
here are interesting postings
Lucene IndexWriter thread safety
Lucene – open a closed IndexWriter
Update:
Exactly 2 years later I did a rest API which wraps this and all writes and reads were routed to the API.
Multiple threads, same process:
Keep your
IndexWriteropened, and share it across multiple thread. TheIndexWriteris threadsafe.For multiple processes, your solution #1 is prone to issues with race conditions. You would need to use named
Mutexto implement it safely:http://msdn.microsoft.com/en-us/library/bwe34f1k.aspx
That being said, I’d personally opt for a process dedicated to writing to the index, and communicate with it using something like WCF.