关于MATSIM中,如何关闭自动加载dtd的问题
2017-01-17 10:26
525 查看
有用过MATSIM做交通仿真的朋友应该都知道,在创建Scenario时,会默认加载matsim官网的netword的dtd文件,然后因为网络的问题,加载往往会报错,从而造成系统异常退出,如图所示:
根据日志提示,得知“罪魁祸首”就是MatsimXmlParser.java这个类中的第215行附近的代码,我们查找源码,找到了原因:
虽然从代码和注释上来看,似乎加载失败并不会对程序造成致命的影响,但是从现象上来看,的确导致了程序的异常退出,并且每次运行都要加载,耗费了时间,我们可以将这段代码注释掉,并修改log日志,验证是否生效:
注意,这个修改后class应该保持和源码结构中相同的包结构,在eclipse中,工程结构如图所示:
保存后再次运行matsim的应用程序,发现不会再加载dtd文件了,而且log日志也确实显示为我们修改后的日志了:
根据日志提示,得知“罪魁祸首”就是MatsimXmlParser.java这个类中的第215行附近的代码,我们查找源码,找到了原因:
// try to get the dtd from the web log.info("Trying to load " + systemId + ". In some cases (e.g. network interface up but no connection), this may take a bit."); try { URL url = new URL(systemId); URLConnection urlConn = url.openConnection(); urlConn.setConnectTimeout(8000); urlConn.setReadTimeout(8000); urlConn.setAllowUserInteraction(false); InputStream is = urlConn.getInputStream(); /* If there was no exception until here, than the path is valid. * Return the opened stream as a source. If we would return null, then the SAX-Parser * would have to fetch the same file again, requiring two accesses to the webserver */ return new InputSource(is); } catch (IOException e) { // There was a problem getting the (remote) file, just show the error as information for the user log.error(e.toString() + ". May not be fatal." ) ; }
虽然从代码和注释上来看,似乎加载失败并不会对程序造成致命的影响,但是从现象上来看,的确导致了程序的异常退出,并且每次运行都要加载,耗费了时间,我们可以将这段代码注释掉,并修改log日志,验证是否生效:
// try to get the dtd from the web log.info("[SKIP] Trying to load " + systemId + ". In some cases (e.g. network interface up but no connection), this may take a bit."); // try { // URL url = new URL(systemId); // URLConnection urlConn = url.openConnection(); // urlConn.setConnectTimeout(8000); // urlConn.setReadTimeout(8000); // urlConn.setAllowUserInteraction(false); // // InputStream is = urlConn.getInputStream(); // /* If there was no exception until here, than the path is valid. // * Return the opened stream as a source. If we would return null, then the SAX-Parser // * would have to fetch the same file again, requiring two accesses to the webserver */ // return new InputSource(is); // } catch (IOException e) { // // There was a problem getting the (remote) file, just show the error as information for the user // log.error(e.toString() + ". May not be fatal." ) ; // }
注意,这个修改后class应该保持和源码结构中相同的包结构,在eclipse中,工程结构如图所示:
保存后再次运行matsim的应用程序,发现不会再加载dtd文件了,而且log日志也确实显示为我们修改后的日志了:
相关文章推荐
- 关于telnet自动关闭连接的问题解答
- 关于解决Windows Server 2003服务器共享服务自动关闭的问题
- 关于浏览器自动加载visadd.com的问题
- 关于tomcat启动完自动执行的问题,初始化问题,加载两次问题
- 关于tomcat启动后马上又自动关闭的问题
- 关于thinkphp5.0 rc4.0扩展类库自动与手动加载的问题
- 关于自动关闭微信浏览器问题
- 关于解决ubuntu中Docky软件断电自动关闭的问题(Linux: Docky Closes After Waking Up From Suspend (Ubuntu 14.04))
- 关于C# 窗体自动隐藏和加载的问题
- 关于LCD自动关闭问题的解决方案(暂时)
- 关于Tomcat自动加载问题
- 关于SAXParser加载dtd报错问题解析
- 【操作系统】关于C语言设计程序退出自动关闭窗口的问题
- 求教关于窗口分割的问题:如何在不关闭窗口的情况下随意更改窗口的分割数目
- 关于首页新进商品,特价商品,推荐商品在后台如何关闭的问题
- PHP关于如何解决表单POST传参数时,自动加转义字符的问题
- winform 关于Messagebox自动定时关闭和自定义提示框总按钮上文本的问题的整理
- 关于把文本文件复制到excel中如何能够自动排列好的问题
- 关于tomcat启动后马上又自动关闭的问题
- 关于Windows8.1应用商店恢复&&APP清理&&关闭开机自动连接go.microsoft.com问题