欢迎使用普元产品知识库,本知识库包含普元应用开发平台EOSPlatform,流程平台BPS,企业服务总线ESB,微服务平台Microservice,运维管理平台Devops,数据集成平台DI

页面树结构

欢迎使用普元文档库

Skip to end of metadata
Go to start of metadata

【问题描述】

 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();
     }
   }
}

  • 无标签