关于MATSIM中,如何关闭自动加载dtd的问题
有用过MATSIM做交通仿真的朋友应该都知道,在创建Scenario时,会默认加载matsim官网的netword的dtd文件,然后因为网络的问题,加载往往会报错,从而造成系统异常退出,如图所示:

根据日志提示,得知“罪魁祸首”就是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日志也确实显示为我们修改后的日志了:

关于MATSIM中,如何关闭自动加载dtd的问题的更多相关文章
- php中 __autoload函数 自动加载类文件机制
魔术函数,自动加载机制function __autoload($class_name) { //自动传递的是类名$path = str_replace('_', '/', $class_name) ...
- 让Lua自己把文件夹下面的所有文件自动加载起来吧
没有想到我也做了一回标题党.其实这里边说的自动还是有夸大其词的部分.其实只是指定文件夹,然后根据指定文件夹数据,加载目录下边的内容而已. 怎么来进行Lua文件的加载 一般情况下,相关的功能需要给他创建 ...
- CI框架源码阅读笔记9 CI的自动加载机制autoload
本篇并不是对某一组件的详细源码分析,而只是简单的跟踪了下CI的autoload的基本流程.因此,可以看做是Loader组件的分析前篇. CI框架中,允许你配置autoload数组,这样,在你的应用程序 ...
- Laravel 执行流程(一)之自动加载
定位 从 public/index.php 定位到 bootstrap/autoload.php 从 bootstrap/autoload.php 定位到 vendor/autoload.php 从 ...
- ThinkPHP5.0源码学习之注册自动加载
ThinkPHP5框架的自动注册加载流程如下:
- lumen之composer自动加载
composer作为PHP的包管理工具,让PHP可以使用命名空间, 载入对应的类文件,不用理会文件引入的路劲问题,代码可读性也大大提高 composer 自动加载 composer 自动加载的规则 v ...
- PHP 自动加载
回顾 开始的时候, 如果想在一个php文件中使用其它文件的类或方法, 需要通过include/require方法将文件包含进来. 这种方法的缺点也很明显: 如果需要引入很多文件, 就需要很多的incl ...
- 29)PHP,自动加载类
(1)作用: 类的自动加载是指,在外面的页面中,并不需要去“引入”(包含)类文件,但是程序会在需要一个类的时候就自动去“动态加载”该类. (2)什么叫做“需要一个类”?通常是这样的情况: 1,创建一个 ...
- PHP中类的自动加载
在之前,我们已经学习过Composer自动加载的原理,其实就是利用了PHP中的类自动加载的特性.在文末有该系列文章的链接. PHP中类的自动加载主要依靠的是__autoload()和spl_autol ...
随机推荐
- HDU 5172 GTY's gay friends 线段树
GTY's gay friends Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- python之路:进阶 二
c = collections.Counter( Counter({ b = collections.Counter( b.update(c) Counter({ Counter({ ...
- 高并发数据库之MySql性能优化
1.慢查询 SHOW VARIABLES LIKE '%quer%'
- spark 文件系统Alluxio(之前名为Tachyon)
http://www.alluxio.org/documentation/v1.0.0/cn/ http://www.winseliu.com/blog/2016/04/15/alluxio-quic ...
- CentOS 7.0 安装配置 kafka 消息队列
查询下载最新版本 kafka http://kafka.apache.org/downloads.html wget http://mirror.bit.edu.cn/apache/kafka/0.8 ...
- Java NIO 与 IO
我应该何时使用 IO,何时使用 NIO 呢?在本文中,我会尽量清晰地解析 Java NIO 和 IO 的差异.它们的使用场景,以及它们如何影响您的代码设计. Java NIO 和 IO 的主要区别 下 ...
- iOS 发布流程
1.登陆苹果开发者中心http://developer.apple.com(99美元账号) 2.进入itunes connect 3.选择Manage Your Apps 4.选择Add New Ap ...
- Spark Standalone Mode
It is very easy to install a Spark cluster (Standalone mode). In my example, I used three machines. ...
- 可用于Windows Server 2008 R2的Xbox One手柄、接收器驱动
让客厅里的Gen8可以玩FC和PS1游戏,折腾了半天,终于将Xbox One手柄驱动弄好: http://www.drvsky.com/Microsoft/Xbox_One.htm http://ww ...
- [repost]Xcode因为证书问题经常报的那些错
[reference]http://www.jianshu.com/p/b10680a32d3 1. 确认下证书是不是开发证书,如果是发布证书就会出现这样的提示. 2. 证书失效了,去开发者中 ...