一、问题背景
环境:linux,tomcat9
问题描述:tomcat执行shutdown.sh之后进程还存在
原因:项目中存在非守护线程Thread.currentThread().setDaemon(false);
二、问题解决
思路:
- 设置线程为守护线程Thread.currentThread().setDaemon(true);
- 记录tomcat进程pid,shutdown时强制关闭进程(本次解决的方法)
以下是采用强制关闭进程的方法
1、在catalina.sh添加如下内容
if [ -z "$CATALINA_PID" ];then
CATALINA_PID=$PRGDIR/CATALINA_PID
fi
2、在shutdown.sh添加如下内容
exec "$PRGDIR"/"$EXECUTABLE" stop -force "$@"