My program loops thru a list of email records, first searches in index for its docid. Once it gets the docid, it will try to remove the doc from the index.
The problem I ran into was: 4 out 10 times I ran the program, I got "Lock obtain timed out: Lock@/tmp/lucene-6c36cae1cb524a61cdbb38a32f2ef684-write.lock" on the last email record I tried to delete. 5 out 10 times it finished just fine. 1 out 10 times it got Lock error when there were more than one email records left to delete (there are totally 29 docs in the index) Here is the code: int i = 0; Iterator<EmailRecord> it = v.iterator(); //v is the vector contains email records while(it.hasNext()){ EmailRecord eml = (EmailRecord)it.next(); // local search function to get the docId, searcher and Directory are closed after search is done int docid = lSearcher.search(eml); // if doc not found, change the status updator if(docid == SystemConfig.ERROR_DOC_NOT_FOUND){ // update database entry updator.setStatus(i, SystemConfig.ERROR_DOC_NOT_FOUND); }else{ Directory indexDir = null; IndexModifier modifier = null; try{ indexDir = FSDirectory.getDirectory(index, false); modifier = new IndexModifier(indexDir, new StandardAnalyzer(), false); modifier.deleteDocument(docid); modifier.flush(); // make sure all the changes pushed to the disk modifier.close(); indexDir.close(); }catch(IOException e){ logger.error("Cannot delete " + docid + " th doc from the index: " + eml.getUsername() + " " + e.getMessage()); updator.setStatus(i, SystemConfig.ERROR_CANNOT_DELETE); } // try to sleep between two deletions try{ Thread.sleep(100); }catch(InterruptedException e){ logger.error("Cannot sleep after one deletion... " + e.getMessage()); } } i++; } Thanks Wenjie