lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Isakson" <Eric.Isak...@sas.com>
Subject RE: IndexReader In a MultiThreaded Env
Date Wed, 16 Apr 2003 21:01:57 GMT
IndexReader will obtain a write.lock when it tries to delete and holds the lock until the reader
is closed or garbage collected.

IndexWriter obtains the write.lock when it is created and holds the lock until the reader
is closed or garbage collected.

So to combat this problem if you can't rely on inter thread communication you might be able
to check for a lock before using the reader.

String index = "path to index";
while (IndexReader.isLocked(index)) {
	// wait a little bit, if we have waited to long compain loudly and die
}

I don't know if this is acceptable for your app. This, or something like it, might do the
job.

Eric

-----Original Message-----
From: Rob Outar [mailto:routar@ideorlando.org] 
Sent: Wednesday, April 16, 2003 4:22 PM
To: Lucene Users List
Subject: IndexReader In a MultiThreaded Env


Hi all,

	I think I tracked down what was a nasty bug.  I have 2 threads, my program works in the following
way, the first time a user tries to access the index, if an index does not exists then one
is built, otherwise if one is there it simply uses it.

	Thread 1 comes along and he tries to query, no index exists (ndexReader.indexExists(File
directory) method) so one is now being built.

	Thread 2 comes along he checks if an index exists via the IndexReader.indexExists(File directory)
method <-- it returns true since all the method does is File.exists().  Since thread one
caused an index to be built Thread 2 thinks that it is a usable index and tries to run queries
and modify the index -- all of which fail because the index is still being built.

	Is there any method that checks more than if the index directory simply exists?  Is there
way to make sure the index is valid before using it?

	Let me know.

Rob


---------------------------------------------------------------------
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


Mime
View raw message