在tomcat7下停止应用时报错:created a ThreadLocal with key of type

在tomcat7下停止应用时报错: created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10]

INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Apr 02, 2015 10:36:52 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Apr 02, 2015 10:36:52 AM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Apr 02, 2015 10:36:52 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
<span style="color:#ff0000;">SEVERE: The web application [/techrevmanager5] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$3] (value [[email protected]]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@7f5846d0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.</span>
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
Apr 02, 2015 10:36:52 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]

先说一下开发环境清单

Tomcat-7.0.59

xwork-core-2.2.1

struts2-core-2.2.1

分析过程

从错误情况来看,是xwork中的类com.opensymphony.xwork2.inject.ContainerImpl出现了问题。

下载xwork-core-2.2.1的源码,打开ContainerImpl文件,看到行557-583中的代码,确实存在内存未释放的问题:

//这里在线程变量中初始化了一维数组
ThreadLocal<Object[]> localContext =
  new ThreadLocal<Object[]>() {
	@Override
	protected Object[] initialValue() {
	  return new Object[1];
	}
  };

/**
* Looks up thread local context. Creates (and removes) a new context if
* necessary.
*/
<T> T callInContext(ContextualCallable<T> callable) {
	Object[] reference = localContext.get();
	if (reference[0] == null) {
	  reference[0] = new InternalContext(this);
	  try {
		return callable.call((InternalContext)reference[0]);
	  } finally {
		// Only remove the context if this call created it.
		reference[0] = null;
		//这里只将数组中的元素释放,并未将线程变量的数组对象释放
	  }
	} else {
	  // Someone else will clean up this context.
	  return callable.call((InternalContext)reference[0]);
	}
}

解决方法

问题和原因都找到,那么解决起来就简单了,有两种方案可以选择:

  1. 升级xwork的jar文件版本,根据我的检查,从xwork-core-2.3.3及以后的版本中这个问题就不存在了。相应地,你可以需要升级你的struts2-core-2.3.3以上。
  2. 修改xwork-core-2.2.1中的com.opensymphony.xwork2.inject.ContainerImpl文件,编译后放入classpath路径下(以取代jar文件中的类)
<T> T callInContext(ContextualCallable<T> callable) {
	Object[] reference = localContext.get();
	if (reference[0] == null) {
	  reference[0] = new InternalContext(this);
	  try {
		return callable.call((InternalContext)reference[0]);
	  } finally {
		// Only remove the context if this call created it.
		reference[0] = null;
		//将线程变量的数组对象释放
		this.localContext.remove();
	  }
	} else {
	  // Someone else will clean up this context.
	  return callable.call((InternalContext)reference[0]);
	}
}
时间: 2024-09-27 08:20:07

在tomcat7下停止应用时报错:created a ThreadLocal with key of type的相关文章

spring注入时报错::No qualifying bean of type &#39;xxx.xxMapper&#39;

做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Autowired, 结果,junit一启动,就报错误:Java.lang.illegalStateException:Failed to load ApplicationContext 具体是在 创建bean的时候报:No qualifying bean of type 'xxx.xxMapper' ab

linux下挂载samba时报错,wrong fs type,bad option,bad superblock

环境:172.24.21.22是samba服务端 使用mount命令直接挂载,如下 居然报错,那我们使用-t 参数,加上cifs 居然还是报错 仔细查看上面的报错,小括号里面的,need a /sbin/mount.<tpye> helper program) 貌似在/sbin/有很多与mount相关的命令,查看如下,使用双tab列出所有/sbin/mount.开头的命令: 貌似少了一个mount.cifs,因为samba使用的文件系统是cifs:那就安装嘛,如下 上面安装mount.cifs

Eclipse JavaEE下引用jdbc时报错:找不到DB驱动及连接的解决方法

搭建购物网站的时候把IDE换成了Eclipse JavaEE.之前在MyEclipse环境下工作时配置jdbc都是直接右击项目通过build path引入相应的jar包,但这种做法在Eclipse下行不通——在调用DB时eclipse会一直提示找不到DB驱动和连接.网上搜索了一下,发现将jdbc的jar包引入到project的WebContent/WEB-INF/lib目录下即可解决问题. 原文连接:http://blog.csdn.net/liyong199012/article/detail

解决iredmail下postfix发送邮件时报错[need fully-qualified hostname]

iredmail配置好后,尝试从一客户端的OE中发送邮件,结果报错,在mail主机中查看tail /var/log/maillog,发现如下错误信息: Oct 24 12:50:49 mail2 postfix/smtpd[9280]: connect from unknown[192.168.5.240] Oct 24 12:50:49 mail2 postfix/smtpd[9280]: NOQUEUE: reject: RCPT from unknown[192.168.5.240]: 5

关于在地址池下绑定IP时报错The IP address‘s status is error解决方法

我使用华为交换机为一家企业里电脑绑定IP地址时报:The IP address's status is error的错误.如下图: 这时我觉得可能这个IP地址已经被DHCP服务给分配到下面电脑了,于是我查了一下华为官方资料,找到一条释放IP命令如下: 这条命令即可以释放单独的IP,也可以释放所有IP,我再回到地址池中绑定IP成功.如下图: 最后保存,退出.OK 原文地址:http://blog.51cto.com/lijie1977/2157718

win10(64位)下memcache安装时报错“ failed to install service or service already installed”

环境: win8(64位)系统 错误提示: failed to install service or service already installed 解决办法: 1.找到cmd.exe文件(c:\windows\system32\cmd.exe) 2.右键cmd.exe以管理员方式运行

Linux下MySql启动时报错

/opt/mysql/support-files/mysql.server startmy_print_defaults: [ERROR] Found option without preceding group in config file /opt/mysql/my.cnf at line 1!my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!Starting MySQL. ERROR!

eclipse下提交job时报错mapred.JobClient: No job jar file set. User classes may not be found.

错误信息: 11/10/14 13:52:07 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.11/10/14 13:52:07 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobCo

win8(64位)下memcache安装时报错“ failed to install service or service already installed” 与安装

解决办法: 1.找到cmd.exe文件(c:\windows\system32\cmd.exe) 2.右键cmd.exe以管理员方式运行 3.把php_memcache.dll放到php的ext目录: 4. 在 php.ini上增加一行:extension=php_memcache.dll 5.cmd进入memcached.exe的目录,然后执行安装memcached.exe -d install  接下来启动memcached.exe -d start