Tomcat 关闭时报错
最近tomcat走普通的关闭方式无法正常关闭,会报一些Error,用的是Tomcat7,据说是Tomcat7在关闭的时候加了一些检查线程泄漏内存泄露的东西
总结起来,在我项目中有这么几个原因会导致关闭不了:
1、使用了@Scheduled注解
最后查出来原因是因为在bean里面使用了 @Scheduled 注解,而Tomcat关闭的时候,spring并不能主动关闭这些Schedule,也就是说这注解有缺陷,慎用。
替代方法就是放弃spring的Scheduled注解方式使用quartz,这里我把所有的spring注解计划任务换回了配置文件:
<bean id="syncProgramQuartz" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="taskProgramSync">
</property>
<property name="targetMethod" value="sync">
</property>
<property name="concurrent" value="false">
</property>
</bean> <bean id="syncProgramQuartzTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="syncProgramQuartz"></property>
<property name="cronExpression">
<value>${SYN_PROGRAM_TASK_CRON}</value>
</property>
</bean> <bean name="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="syncProgramQuartzTrigger" />
</list>
</property>
</bean>
这样就不报 pool-xxxx-1无法关闭之类的错误了。
2、连接池没有手动关闭
这个也是在自定义的Listener里面处理,代码如下
new Thread() {
public void run() {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
try {
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}.start();
3、AbandonedConnectionCleanupThread单独关闭,这个在关完连接池后就顺便一起关了吧
try {
AbandonedConnectionCleanupThread.shutdown();
} catch (InterruptedException e) {
e.printStackTrace();
}
一般做完以上三步就差不多了。
4、个别线程强行阻碍
对于这种管不了的线程我们就根据其线程名将其关闭
Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) {
if(thread.getName().equals("xxxxxxthread")){
try {
thread.interrupt();
System.out.println(thread.getName()+" is stopped");
return;
} catch (Exception e) {
System.out.println(thread.getName()+" stop error");
e.printStackTrace();
}
}
}
Tomcat 关闭时报错的更多相关文章
- TOMCAT启动时报错:the CATALINA_HOME environment variable is not defined correctly
运行tomcat/bin目录下的startup.bat时报错:the CATALINA_HOME environment variable is not defined correctly 碰到这个问 ...
- Tomcat启动时报错:java.net.BindException: Permission denied <null>:80 【转载】
本文转载自: http://blog.sina.com.cn/s/blog_4550f3ca0101g37l.html 问题起因:做负载均衡时需要将Web工程与Wap工程同时部署在一台Suse服务 ...
- Tomcat启动时报错:“ Error starting static Resources”问题解决
部署测试环境的时候,需要用到Tomcat.故在Linux上部署了Tomcat,并将开发提供的工程包部署到Tomcat的webapps目录下,启动Tomcat,部署成功.第二天修改工程配置文件时,发现w ...
- TOMCAT 关闭报错:Tomcat did not stop in time. PID file was not removed
关闭tomcat的时候,报出如下错误信息: # ./shutdown.sh Using CATALINA_BASE: /opt/openkm-6.3.1-community/tomcat Using ...
- C# 移动开发 MasterDetailPage 关闭时报错问题
至上次发表的 MasterDetailPage界面做主App,折腾10天,终于知道问题所在.. 泪奔的是解决这个问题只要一句代码 在MainActivity.cs里 [Activity(Label = ...
- Tomcat启动时报错,Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext
05-Dec-2016 11:23:44.321 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addCh ...
- Tomcat启动时报错:java.net.UnknownHostException
异常信息如下: INFO: Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll ad ...
- Eclipse4.6安装Tomcat插件时报错:Unable to read repository at http://tomcatplugin.sf.net/update/content.xml. Received fatal alert: handshake_failure
错误如下: Unable to read repository at http://tomcatplugin.sf.net/update/content.xml.Received fatal aler ...
- [spring+tomcat]启动时报错:NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
一般来讲问题的原因为tomcat版本较低, 建议升级到tomcat7x 以上版本
随机推荐
- lucas定理 FOJ 2020 组合
Problem 2020 组合 Accept: 886 Submit: 2084Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- python 3.x和2.x不同和改动
参考于http://www.runoob.com/python/python-2x-3x.html 因为这几天换了电脑,之前电脑里装的是python2.x,因为那时候刚学的时候,很多教程都是用2.x. ...
- Current limiter allows large USB bypass capacitance
The USB (Universal Serial Bus) specification requires a connected USB device to present a load to th ...
- 几个未公开的 DBCC 命令
http://blog.csdn.net/CathySun118/article/category/538610 https://ask.hellobi.com/blog/lyhabc/1612 1. ...
- (转)SQL Server创建索引
什么是索引拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音.笔 ...
- ice地址
http://www.zeroc.com/download/eclipse
- jdbc分页
分页是一个被讲到烂掉的话题,今天我再拾起来踹几脚吧 (Hibernate的分页做得很好很强大,用的人都知道 ,这个就不用再说了) 1.为什么要分页? 首先是数据量太大会影响查询和传输的性能,关键 ...
- 【资料】wod书籍
世界掉落 特点 风化的书卷 可用三次的无限耗材 华丽的书卷 可用5次 无限耗材 队伍唯一 抄录页:新手躲避 近远防御 +34%X技能等级 风化的书卷:新手躲避 华丽的书卷:新手躲避 抄录页:高级闪避技 ...
- golang的缓冲channel和无缓冲channel的区别
话说golang的channel同步的定义真是让人无力吐槽,码农的用户体验就这么难搞么,超耐磨阿,无缓冲和缓冲居然有这么大区别....靠 转载一段网上的资料 --------------------- ...
- 9.线程通信wait、notify
线程之间通信 1.线程是操作系统的独立的个体,但这些个体如果不经过特殊处理就不能成为一个整体. 2.使用wait.notify,方法实现线程通信(2个方法都是需要object方法) 3.wait(释放 ...