Tomcat サーバーから取得した大量のログ ファイルのインデックスを作成しようとしています。各ファイルを開き、各行のインデックスを作成し、Apache lucene を使用して各行を保存するコードを作成しました。これらはすべてマルチスレッドを使用して行われます。
このコードを実行しようとすると、この例外が発生します
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();
今、私は例外を取得しません
Q. 私の質問は、なぜ indexWriter.commit(); なのかということです。例外が発生します。indexWriter.commit(); を削除しても 検索中に問題はありません。つまり、意図したとおりの結果が得られます。次に、なぜ indexWriter.commit(); を使用するのですか? ?