PAS部署:PAS中部署应用,卸载应用后线程仍在运行

当在PAS平台卸载应用时,可能会出现线程未完全停止的问题,导致资源占用。解决这个问题有两种方案:一是通过重启PAS(如果应用部署在独立实例/集群,则重启实例/集群)来强制停止线程;二是应用程序内部实现监听关闭并手动回收线程,例如通过遍历线程组,中断并停止非主线程。这样做可以确保应用卸载后所有线程被正确清理。
摘要由CSDN通过智能技术生成

【问题描述】

 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;
     } 
     if (Thread.currentThread() != thread &&!"main".equals(thread.getName())) {
        thread.interrupt();
        thread.stop();
     }
   }
}

【原文链接】

http://doc.primeton.com/pages/viewpage.action?pageId=82157209

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值