单元测试报connection is allready closed导致dailybuild中断的解决方案——类加载机制的应用
public void afterTestMethod(Object testInstance, Method testMethod, Throwable exception) throws Exception {
Assert.notNull(testInstance, "testInstance must not be null");
if (logger.isTraceEnabled()) {
logger.trace("afterTestMethod(): instance [" + testInstance + "], method [" + testMethod +
"], exception [" + exception + "]");
}
getTestContext().updateState(testInstance, testMethod, exception); // Traverse the TestExecutionListeners in reverse order to ensure proper
// "wrapper"-style execution of listeners.
List<TestExecutionListener> listenersReversed =
new ArrayList<TestExecutionListener>(getTestExecutionListeners());
Collections.reverse(listenersReversed); Exception afterTestMethodException = null;
for (TestExecutionListener testExecutionListener : listenersReversed) {
try {
testExecutionListener.afterTestMethod(getTestContext());
}
catch (Exception ex) {
logger.warn("Caught exception while allowing TestExecutionListener [" + testExecutionListener +
"] to process 'after' execution for test: method [" + testMethod + "], instance [" +
testInstance + "], exception [" + exception + "]", ex);
if (afterTestMethodException == null) {
afterTestMethodException = ex;
}
}
}
if (afterTestMethodException != null) {
// 捕获这种异常,不再抛出
if (afterTestMethodException.getMessage ().indexOf ("Connection has already been closed") > -1) {
logger.error ("catch the exp!", afterTestMethodException);
return;
}
throw afterTestMethodException;
}
}
再次执行5次dailybuild,问题没有再现。
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null) {// 找不到的时候才会作为新的类加载
long t0 = System.nanoTime();
try {
if (parent != null) {
c = parent.loadClass(name, false);
} else {
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
} if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
long t1 = System.nanoTime();
c = findClass(name); // this is the defining class loader; record the stats
sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
sun.misc.PerfCounter.getFindClasses().increment();
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}

如上图,classloader先加载的是项目编译生成的class,因此,同一个类,如果在项目中存在的话,就不会再加载jar包中的类了。
单元测试报connection is allready closed导致dailybuild中断的解决方案——类加载机制的应用的更多相关文章
- Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)
公司一SQL Server镜像发生了故障转移(主备切换),检查SQL Server镜像发生主备切换的原因,在错误日志中发现下面错误: Date 2019/8/31 14:09:17 ...
- Spring事务报Connection is read-only
昨天做项目时,写了个方法,程序突然报了Connection is readonly. Queries leading to data modification are not allowed调了程序半 ...
- 安装好的虚拟机,外部通过ssh工具连接,报connection failed
今天,新装了一台ubuntu虚拟机,安装成功以后,准备利用Xshell从外部访问linux,以减少切换,但是,在连接时,总是会报:connection failed. 于是,写下这篇随笔,以增加记忆且 ...
- main方法或者junit单元测试报 类找不到异常
MyEclipse10.7+Maven项目junit单元测试报找不到类异常,附正常编译后的输出设置 1 首先想到的是输出路径错误 一般不是maven工程的项目编译后的.class文件会在/weba ...
- 【centOS】【xshell】xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host
如题 xshell连接虚拟机上的centOS,操作途中突然断开连接,报错:connect closed by foreign host 快捷解决方法: 在虚拟机上centOS重新启动网络,即可解决问 ...
- An existing connection was forcibly closed by the remote host
StackOverflow https://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-con ...
- junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题
junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...
- By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds.
WebSocket proxying https://nginx.org/en/docs/http/websocket.html By default, the connection will be ...
- MySQL中char(36)被认为是GUID导致的BUG及解决方案
MySQL中char(36)被认为是GUID导致的BUG及解决方案 有时候在使用Toad或在程序中,偶尔会遇到如下的错误: System.FormatException GUID 应包含带 4 个短划 ...
随机推荐
- 用html5调取谷歌地图获取位置
function getmap(){ if(!navigator.geolocation) throw "Geolocation not supported"; var image ...
- javascript中document.form[formName][]的意思
近来重新学习javascript发现还有很多知识点模糊,今天就javascript中的document.forms[formName][inputName]进行说明: <!DOCTYPE htm ...
- 编译MapWinGis
其实在github下载的MapWinGIS代码,在support文件夹下的build文件夹下的HowToBuild说明已经写的很清楚了, * How to build MapWinGIS.ocx** ...
- 【PHP】最详细PHP从入门到精通(三)——PHP中的数组常用函数汇总
PHP从入门到精通 之PHP中的数组常用函数详解 数组作为PHP中最常用的结构之一,PHP强大的数组函数功能,给数组的相关操作带来了极大的便利.今天给大家介绍的PHP中数组函数,是PHP数组中重要的 ...
- [译]WPF MVVM 架构 Step By Step(5)(添加actions和INotifyPropertyChanged接口)
应用不只是包含textboxs和labels,还包含actions,如按钮和鼠标事件等.接下来我们加上一些像按钮这样的UI元素来看MVVM类怎么演变的.与之前的UI相比,这次我们加上一个"C ...
- mac os 安装PIP 及异常“”Can't install python module: PyCharm Error: “byte-compiling is disabled, skipping”“”的解决方案
For all who have the same problem, it took me a while to find the solution in a new installation of ...
- react-native-fs插件的使用以及遇到的坑
react-native-fs插件是文件对上传和下载时使用的,iOS和android都可使用,File upload (iOS only). 安装命令: npm install react-nativ ...
- java http请求,字节流获取百度数据
请求的地址为: http://api.map.baidu.com/place/v2/search?&q=%E9%A5%AD%E5%BA%97®ion=%E9%87%8D%E5%B ...
- C++数组概述
C++数组概述 基本概念 1. 数组是固定大小的一种复合类型 因为数组是固定大小,所以在编译期间就决定了基大小 数组的内存是连续(无论是一维数组还是多维数组) 2. 数组的特性 数组之间不允许拷贝和赋 ...
- Android 音乐播放
android简单音乐播放控制代码 这个几个月业余时间一直在做一个android项目,里面涉及到了音乐播放功能.很简单那种,播放.暂停.上一曲.下一曲.音量调节等. 音乐播放主要使用的对象是Media ...