LockObtainFailedException: Lock obtain timed out:

1630 ワード

学習luceneテストインデックス全削除時報異常
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@F:\Lucene&solr\index\write.lock
	at org.apache.lucene.store.Lock.obtain(Lock.java:89)
	at org.apache.lucene.index.IndexWriter.(IndexWriter.java:753)
	at com.itheima.lucene.luceneManager.getIndexWriter(luceneManager.java:22)
	at com.itheima.lucene.luceneManager.testAllDelete(luceneManager.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at 。。。。

コード:
public IndexWriter getIndexWriter() throws IOException{
		Analyzer analyzer = new StandardAnalyzer();
		IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_4_10_3, analyzer);
		Directory directory = FSDirectory.open(new File("F:\\Lucene&solr\\index"));
		return new IndexWriter(directory, config);
	}
	@Test
	public void testAllDelete() throws Exception {
		getIndexWriter().deleteAll();
		getIndexWriter().close();
		
	}

修正後正常
public IndexWriter getIndexWriter() throws IOException{
		Analyzer analyzer = new StandardAnalyzer();
		IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_4_10_3, analyzer);
		Directory directory = FSDirectory.open(new File("F:\\Lucene&solr\\index"));
		return new IndexWriter(directory, config);
	}
	@Test
	public void testAllDelete() throws Exception {
		IndexWriter indexWriter = getIndexWriter();
		indexWriter.deleteAll();
		indexWriter.close();
		
	}

前者が2つの書き込みストリームを作成した理由