我想索引从tomcat服务器获取的一大组日志文件。我编写了代码打开每个文件,为每行创建索引,然后使用Apache lucene存储每行。所有这些都是使用多线程完成的。org.apache.lucene.store.LockObtainFailedException:锁定获取超时:
我得到这个异常,当我尝试这种代码
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
代码
if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
{
// New index, so we just add the document (no old document can be there):
System.out.println("adding " + path);
indexWriter.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been indexed) so
// we use updateDocument instead to replace the old one matching the exact
// path, if present:
System.out.println("updating " + path);
indexWriter.updateDocument(new Term("path", path), doc);
}
indexWriter.commit();
indexWriter.close();
现在我想,因为我每次都犯了索引,则可能会导致一个写锁。所以我删除indexWriter.commit();
:
if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
{
// New index, so we just add the document (no old document can be there):
System.out.println("adding " + path);
indexWriter.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been indexed) so
// we use updateDocument instead to replace the old one matching the exact
// path, if present:
System.out.println("updating " + path);
indexWriter.updateDocument(new Term("path", path), doc);
}
indexWriter.close();
现在我得到也不例外
问:所以我的问题是,为什么indexWriter.commit();导致异常。即使我删除indexWriter.commit();我在搜索时没有遇到任何问题。那是我得到我想要的确切结果。那么为什么要使用indexWriter.commit(); ?