如何在java中刷新网络名称的解析



我目前正在编写一个Java EE应用程序,使用Lucene搜索索引。

我的应用程序驻留在Windows机器上的Tomcat服务器上,索引数据在另一台机器上。

有时(显然是随机的),网络名变得不可达。

这是我得到的例外:

12:29:39.011 [ajp-8039-5] ERROR o.f.c.d.p.viewmodel.PilotViewModel - The specified network name is no longer available: SimpleFSIndexInput(path="\INDEXFILEPATHindexfile.ext")
java.io.IOException: The specified network name is no longer available: SimpleFSIndexInput(path="\INDEXFILEPATHindexfile.ext")
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput.readInternal(SimpleFSDirectory.java:140) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]

下面是相关代码。在FSDirectory.open

上抛出异常。
private void addReaderForRegistry(String indexDirectoryPath, List<IndexReader> readers) throws IOException{
    File indexFolder = new File(indexDirectoryPath);
    if (!(indexFolder.exists() || !(indexFolder.isDirectory()))) {
          throw new IOException(indexFolder.getName() + "is not a valid index location");
    }else{
        // search for subfolders
        List<String> subfolders = FileSystemHelper.listDirectories(indexFolder.getAbsolutePath());
        if(subfolders.isEmpty()){
            Directory fsDirectory = FSDirectory.open(indexFolder);
            IndexReader reader = IndexReader.open(fsDirectory);
            readers.add(reader);                
        }
    }
}

我确定服务器已启动。

要解决这个问题,我必须重新启动Tomcat应用服务器。我能做些什么来做一些错误恢复吗?

请注意,FSDirectory在每次请求时都打开,因此简单的bean重新初始化不起作用。

谢谢。

编辑:这里是一个更完整的堆栈跟踪

java.io.IOException: The specified network name is no longer available: SimpleFSIndexInput(path="\hqwprceb1DRMS-STRUCTUREindexes_readyAG_o48.nrm")
at org.apache.lucene.store.SimpleFSDirectory$SimpleFSIndexInput.readInternal(SimpleFSDirectory.java:140) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:156) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.index.SegmentNorms.bytes(SegmentNorms.java:164) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.index.SegmentReader.norms(SegmentReader.java:575) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.TermQuery$TermWeight.scorer(TermQuery.java:107) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:298) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.ConstantScoreQuery$ConstantWeight.scorer(ConstantScoreQuery.java:145) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:298) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:577) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:383) ~[lucene-core-3.6.1.jar:3.6.1 1362471 - thetaphi - 2012-07-17 12:40:12]

我有一个类似的问题(有时丢失一个网络驱动器,后来自动回来;IndexSearcher没有从中恢复)。

我的解决方法是捕获IndexSearcher#search调用中很少发生的IOException,然后删除这个IndexSearcher实例(将对它的引用设置为null)。下一个请求惰性地创建一个新的IndexSearcher实例(此时也可能失败),希望网络驱动器现在可用。系统迟早会自愈的。

我使用lucene 3.5, JDK 1.6和Windows 7。

如果有人知道更好的解决方案->谢谢你指出来。

看看下面的设置。

http://www.vertigrated.com/blog/2009/11/disable-default-java-dns-caching/

最新更新