最近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 关闭时报错的更多相关文章

  1. TOMCAT启动时报错:the CATALINA_HOME environment variable is not defined correctly

    运行tomcat/bin目录下的startup.bat时报错:the CATALINA_HOME environment variable is not defined correctly 碰到这个问 ...

  2. Tomcat启动时报错:java.net.BindException: Permission denied <null>:80 【转载】

    本文转载自: http://blog.sina.com.cn/s/blog_4550f3ca0101g37l.html   问题起因:做负载均衡时需要将Web工程与Wap工程同时部署在一台Suse服务 ...

  3. Tomcat启动时报错:“ Error starting static Resources”问题解决

    部署测试环境的时候,需要用到Tomcat.故在Linux上部署了Tomcat,并将开发提供的工程包部署到Tomcat的webapps目录下,启动Tomcat,部署成功.第二天修改工程配置文件时,发现w ...

  4. 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 ...

  5. C# 移动开发 MasterDetailPage 关闭时报错问题

    至上次发表的 MasterDetailPage界面做主App,折腾10天,终于知道问题所在.. 泪奔的是解决这个问题只要一句代码 在MainActivity.cs里 [Activity(Label = ...

  6. 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 ...

  7. Tomcat启动时报错:java.net.UnknownHostException

    异常信息如下: INFO: Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll ad ...

  8. 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 ...

  9. [spring+tomcat]启动时报错:NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I

    一般来讲问题的原因为tomcat版本较低, 建议升级到tomcat7x 以上版本

随机推荐

  1. bzoj 1415 无环期望

    #include <cstdio> #include <vector> #include <queue> #include <algorithm> #d ...

  2. Mysql -- 设置中国时区时间

       Mysql -- 设置中国时区时间 查看mysql的时区设置 mysql> show variables like '%time_zone%'; 修改mysql的时区设置, 注:mysql ...

  3. 普及向 ZKW线段树!

    啊,是否疲倦了现在的线段树 太弱,还递归! 那我们就欢乐的学习另外一种神奇的线段树吧!(雾 他叫做zkw线段树   这个数据结构灰常好写(虽然线段树本身也特别好写……) 速度快(貌似只在单点更新方面比 ...

  4. 微信小程序缓存滑动距离,当页面浏览到一定位置,滑动其他页面后返回该页面记录之前的滑动距离

    15.微信小程序缓存滑动距离 我们在浏览页面的时候,然后左滑或者右滑到新的页面,等返回此页面,我们希望可以记录上次滑动的距离 虽然这个实现起来并不难,但是会遇到一些坑,因为scroll-view的组件 ...

  5. 应该用H5编写APP还是用原生的呢?

    现观目前市场上的APP横行,不同行业.不同类目的APP在国内各大应用市场挤爆的满满了,那么作为一个程序员或者一个企业如何能从容的把握住制作一款实用又符合用户体验的APP呢? 自从接触APP也有四年多了 ...

  6. SecureCRT也能和Xshell一样批量导入主机

    在Xshell可以像这样一个文件批量导入主机: https://blog.netsarang.com/91/importing-csv-formatted-host-information-to-xs ...

  7. VS2010 + IDA SDK 搭建IDA Plugin开发环境

    http://www.h4ck.org.cn/2011/11/vs2010-idasdk6-2-ida-plugin-development/ 1. 执行菜单的File->New->Pro ...

  8. 经典笛卡尔积SQL

    经典笛卡尔积SQL: 下面的SQL会造成笛卡尔积: insert into tydic.temp_0731 select a.user_id,a.province_code,b.attr_code f ...

  9. Linux开发环境必备十大开发工具

    Linux是一个优秀的开发环境,但是如果没有好的开发工具作为武器,这个环境给你带来的好处就会大打折扣.幸运的是,有很多好用的Linux和开源开发工具供你选择,如果你是一个新手,你可能不知道有哪些工具可 ...

  10. Js的在线代码编辑器:CodeMirror

    github地址:https://github.com/codemirror/CodeMirror/tree/master/demo 里面包含需要的js.css文件以及大量的示例 官网:https:/ ...