• 解决org.apache.lucene.store.AlreadyClosedException: this Directory is closed


    在Lucene中,关闭一个IndexWriter时抛出AlreadyClosedException异常:

    org.apache.lucene.store.AlreadyClosedException: this Directory is closed

    at org.apache.lucene.store.BaseDirectory.ensureOpen(BaseDirectory.java:66) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.store.FSDirectory.deleteFile(FSDirectory.java:269) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexFileDeleter.deleteFile(IndexFileDeleter.java:595) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexFileDeleter.deleteNewFiles(IndexFileDeleter.java:582) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.deleteNewFiles(IndexWriter.java:4693) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.DocumentsWriter$DeleteNewFilesEvent.process(DocumentsWriter.java:739) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.processEvents(IndexWriter.java:4746) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.processEvents(IndexWriter.java:4738) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.doFlush(IndexWriter.java:3198) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.flush(IndexWriter.java:3170) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.closeInternal(IndexWriter.java:991) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:935) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:897) ~[lucene-core-4.8.1.jar:4.8.1 1594670 – rmuir – 2014-05-14 19:22:52]

    有人说这是因为index目录下的write.lock没有被删除,其实并不是这样。

    真正的原因是,IndexWriter依赖于一个Directory,当Directory关闭的时候,IndexWriter也就随之关闭了。所以正确的关闭顺序是

    1. 先关闭IndexWriter

    2. 后关闭Directory

  • 相关阅读:
    Nim教程【七】
    Nim教程【六】
    博客园博客撰写工具【开源】(可以直接黏贴图片)
    Nim教程【五】
    Nim教程【四】
    Nim教程【三】
    Nim教程【二】
    Nim教程【一】
    开发人员面试题目分享(来看看不一样的面试题吧)【第二弹】
    基于.net开发chrome核心浏览器【七】
  • 原文地址:https://www.cnblogs.com/a-du/p/6950207.html
Copyright © 2020-2023  润新知