1. 程式人生 > >lucene 寫入索引時發生Lock obtain timed out異常

lucene 寫入索引時發生Lock obtain timed out異常

IndexWriter writer = new IndexWriter(this.lucenePath, new SimpleGBKAnalyzer(),false);
執行這行程式碼時報了下面的異常,
java.io.IOExceptionjava.io.IOException: Lock obtain timed out: [email protected]:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\lucene-0bba314bcfc153d3542e4ea3752d383c-write.lock。

原因是 \lucene\index 下面沒有cfs索引檔案,
將 IndexWriter writer = new IndexWriter(this.lucenePath, new SimpleGBKAnalyzer(),false);
最後的引數false 改成 true 後,會在\lucene\index 下面建立cfs索引檔案,然後將引數true重新改成false後,就不會報錯了,原因是false是追加索引,而true為全新建立,追加索引時目錄下面的索引檔案不存在時就丟擲了異常。