有用过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的问题的更多相关文章

  1. php中 __autoload函数 自动加载类文件机制

    魔术函数,自动加载机制function __autoload($class_name) {   //自动传递的是类名$path = str_replace('_', '/', $class_name) ...

  2. 让Lua自己把文件夹下面的所有文件自动加载起来吧

    没有想到我也做了一回标题党.其实这里边说的自动还是有夸大其词的部分.其实只是指定文件夹,然后根据指定文件夹数据,加载目录下边的内容而已. 怎么来进行Lua文件的加载 一般情况下,相关的功能需要给他创建 ...

  3. CI框架源码阅读笔记9 CI的自动加载机制autoload

    本篇并不是对某一组件的详细源码分析,而只是简单的跟踪了下CI的autoload的基本流程.因此,可以看做是Loader组件的分析前篇. CI框架中,允许你配置autoload数组,这样,在你的应用程序 ...

  4. Laravel 执行流程(一)之自动加载

    定位 从 public/index.php 定位到 bootstrap/autoload.php 从 bootstrap/autoload.php 定位到 vendor/autoload.php 从 ...

  5. ThinkPHP5.0源码学习之注册自动加载

    ThinkPHP5框架的自动注册加载流程如下:

  6. lumen之composer自动加载

    composer作为PHP的包管理工具,让PHP可以使用命名空间, 载入对应的类文件,不用理会文件引入的路劲问题,代码可读性也大大提高 composer 自动加载 composer 自动加载的规则 v ...

  7. PHP 自动加载

    回顾 开始的时候, 如果想在一个php文件中使用其它文件的类或方法, 需要通过include/require方法将文件包含进来. 这种方法的缺点也很明显: 如果需要引入很多文件, 就需要很多的incl ...

  8. 29)PHP,自动加载类

    (1)作用: 类的自动加载是指,在外面的页面中,并不需要去“引入”(包含)类文件,但是程序会在需要一个类的时候就自动去“动态加载”该类. (2)什么叫做“需要一个类”?通常是这样的情况: 1,创建一个 ...

  9. PHP中类的自动加载

    在之前,我们已经学习过Composer自动加载的原理,其实就是利用了PHP中的类自动加载的特性.在文末有该系列文章的链接. PHP中类的自动加载主要依靠的是__autoload()和spl_autol ...

随机推荐

  1. 强制删除sql用户链接

    SELECT 'alter system kill session '''||sid||','||serial#||''';' FROM v$session WHERE username='USER' ...

  2. Android网络开发之Volley--Volley基本用法ImageRequest(三)

    1.ImageRequest用法和StringRequest一样,主要分为3步: (1).实例化一个RequestQueue对象 (2).设置ImageRequest对象参数,并将ImageReque ...

  3. ecos的app生命周期

    5种变迁,安装.更新.启动.暂停.卸载,每个app都可以自行维护每种变迁 方法简单,只需要在app/$app_name目录下定义task.php文件 <?php class desktop_ta ...

  4. 2016"百度之星" - 资格赛(Astar Round1) Problem D

    排个序,map直接搞. #include <stdio.h> #include <math.h> #include<cstring> #include<cma ...

  5. CodeForces 616A Comparing Two Long Integers

    水题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; ...

  6. nginx 设置进程title

    刚好看到nginx设置进程title的源码,因此做一些总结. linux进程实际是以argv[0]处的值来作为进程的title的,因此若需要修改进程的title只需要修改argv[0]处的值即可. 简 ...

  7. Mysql(集群)业务水平切割 垂直切割(Amoeba)

     Amoeba原理戳这里:Amoeba详细介绍 需要根据企业 数据业务进行切割,垂直切割又称为纵向切割. 垂直切割通说的说就是有多个表,对表进行分离(用户数据.博客文章数据.照片数据.标签数据类型.群 ...

  8. golang中container/heap包源码分析

    学习golang难免需要分析源码包中一些实现,下面就来说说container/heap包的源码 heap的实现使用到了小根堆,下面先对堆做个简单说明 1. 堆概念 堆是一种经过排序的完全二叉树,其中任 ...

  9. 不小心删掉root目录......

    1.先保存还剩下的的东西,比如说桌面的文件,保存在/下面其他目录 2.执行命令 cp -R /etc/skel/.[!.]* ./ 3.reboot

  10. SQL复习一(基础知识)

    1.什么是sql SQL(structure query language)是结构化查询语言,它是对关系型数据库的操作语言.它可以应用到所有的数据库中,例如:MySQL.Oracle.SQL serv ...