LockObtainFailedException: Lock obtain timed out:

学习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();
		
	}

应该是前者创建了两个写入流的原因

你可能感兴趣的:(LockObtainFailedException: Lock obtain timed out:)