Friday, October 7, 2011

While creating index files for Lucene 3.0.2 search engine I got below mentioned error.

Exception: Lock obtain timed out: NativeFSLock@/export/home/Lucene/indexFiles/write.lock
        at org.apache.lucene.index.IndexWriter.init(
        at org.apache.lucene.index.IndexWriter.(

Solution :

Check for IndexWriter object. Make sure you close IndexWriter object after completing index creation.
Check for any exceptions and close IndexWriter object if exception occurs.

Possible reason is there may be any exception occurred and you missed to close the IndexWriter object in catch block.

code snippte:

// Store the index in file
Directory directory = new SimpleFSDirectory(new File(indexLoc));     
IndexWriter iwriter = new IndexWriter(directory, analyzer, isNew,MaxFieldLength.UNLIMITED);


If you need complete tested code for Lucene 3.0.2 example, click here