【问题描述】

 PAS中部署应用,应用卸载后有遗漏线程,导致有多个线程仍在运行

【解决方案】

方案一:重启, 应用部署在默认server上重启PAS,部署在独立实例/集群上重启独立实例/集群,重启后线程即可停止。

方案二: 应用程序中监听程序关闭,手动回收自己的线程。
示例代码如下:

public void killThread() {
// 当前线程所在的线程组
ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
// 线程组中活跃的线程数
int threadCount = currentGroup.activeCount();
Thread[] threads = new Thread[threadCount];
// 拿到线程组下面的所有线程
currentGroup.enumerate(threads);
// 回收线程
for (int i = 0; i < threads.length; i++) {
Thread thread = threads[i];
if (thread == null) {
continue;
}
i
f (Thread.currentThread() != thread &&
!
"main".equals(thread.getName())) {
thread.interrupt();
thread.stop();
}
}
}