关于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 ...
随机推荐
- json转义字符串
json前台写数据 @RequestMapping("/addUserJson") public void addUserJson(User user,HttpServletReq ...
- Freemodbus 1.5
源:http://blog.sina.com.cn/s/blog_4935209001012eax.html 网站位置:http://www.freemodbus.org/index.php?lang ...
- (中等) CF 585B Phillip and Trains,BFS。
The mobile application store has a new game called "Subway Roller". The protagonist of the ...
- [转] SpringJdbc的几种不同的用法
转自:http://vsp.iteye.com/blog/1182887 Spring对jdbc做了良好的封装,本人在学习时做了以下几种方式的尝试 首页先来创建一个dao接口 package com. ...
- andorid之摄像头驱动流程--MTK平台
原文地址:andorid之摄像头驱动流程--MTK平台 作者:守候心田 camera成像原理: 景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过D ...
- Python正则表达式,统计分析nginx访问日志
目标: 1.正则表达式 2.oop编程,统计nginx访问日志中不同IP地址出现的次数并排序 1.正则表达式 #!/usr/bin/env python # -*- coding: utf-8 -*- ...
- log4cxx第三篇----使用多个logger
使用多个logger时,所有logger的配置写在一个配置文件里面 两个例子: 1 一个继承的例子(http://logging.apache.org/log4cxx/) // file com/fo ...
- linux下源码编译安装mysql
1.安装依赖的包: yum install -y gdb cmake ncurses-devel bison bison-devel 2.创建mysql安装目录和数据文件目录 mkdir -p /us ...
- address2line 定位 Android c++奔溃位置
Android调用c++出现奔溃,崩溃信息为如下: 10-11 15:15:13.541 D/AudioMTKStreamOut( 139): write(), buffer = 0x42bd9390 ...
- IOS开发-OC学习-kvc,kvo
kvc是用来方便的设置实例的属性值的,比如person类的实例p1有一个name的属性,那么我们可以通过kvc去设置p1的name,语法是: [ 对象 setValue:@"xiaming& ...