如何在部署 liferay portlet 之前杀死所有线程

How to kill all the threads before deploying a liferay portlet

我将 Liferay 6.2 与使用 ServletContextListener 创建的线程一起使用。

因此,当我尝试部署这个特定的 portlet 应用程序时,出现以下错误 -

INFO: Illegal access: this web application instance has been stopped already.  Could not load com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at javax.xml.parsers.FactoryFinder.getProviderClass(FactoryFinder.java:112)
    at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:178)
    at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:147)
    at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:265)
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:121)
    at com.h5g.deployment.util.DeploymentUtil.getLobbyBranch(DeploymentUtil.java:642)
    at com.h5g.deployment.service.ClientStatusCheckTask.call(ClientStatusCheckTask.java:47)
    at com.h5g.deployment.service.ClientStatusCheckTask.call(ClientStatusCheckTask.java:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

我一直在寻找一种在自动部署开始之前终止线程的方法。

任何指点都会很有帮助。

尝试使用 for:

停止线程
thread.interrupt();

但我不确定我是否需要查看启动线程的代码

这听起来很像您自己创建线程 - 这通常会在应用程序服务器环境中引起注意。有几种方法可以缓解这种情况 - 对您当前(隐含的)体系结构影响最小的一种方法是,当您 取消部署 Web 应用程序时,您需要停止线程。我假设这不会发生 "on deploy",而是 "after undeploy",因为您在 ServletContextListener 中启动您的线程,但永远不会停止它们。

A ServletContextListener 会在应用程序关闭时收到通知,您可以使用它来将其状态标记给您生成的线程。在典型的无限循环中,线程会经常检查它们是否仍应为 运行 - 如果不应该,则退出无限循环,它们会在它们后面进行漂亮的清理。重新部署应用程序时,新的 ServletContextListener 将生成新线程。