gpt4 book ai didi

java - Tomcat 提示一个线程没有被停止

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:00:27 25 4
gpt4 key购买 nike

我收到有关线程正在启​​动但未结束或停止的异常。 WebappClassLoader 提示这些线程会导致内存泄漏。

这里发生了什么?

  1. 这样的线程是否可能会导致内存泄漏?或者只是可能?
  2. Catalina 是否过于敏感?
  3. 这甚至是一种有效的编程技术吗?

(管理 Tomcat 应用程序的这一方面对我来说是新的。但我必须学习它,因为 web 应用程序在高负载下耗尽了数据库连接,这需要解决。搜索内存泄漏是众多问题之一我们正在研究的事情。)

最佳答案

您可以在 http://wiki.apache.org/tomcat/MemoryLeakProtection 阅读有关 Tomcat 中棘手的内存泄漏问题(尤其是此警告)的信息-- 特别是对于您看到的警告:

If a webapp creates a thread, by default its context classloader is set to the one of the parent thread (the thread that created the new thread). In a webapp, this parent thread is one of tomcat worker threads, whose context classloader is set to the webapp classloader when it executes webapp code.

Furthermore, the spawned thread may be executing (or blocked in) some code that involves classes loaded by the webapp, thus preventing the webapp classloader from being collected.

So, if the spawned thread is not properly terminated when the application is stopped, the webapp classloader will leak because of the strong reference held by the spawned thread.

当您启动 Web 应用程序一次,然后简单地将其拆除时,这种影响(根据我的经验)是有限的。但是,在某些情况下,例如在持续集成场景中(您的 CI 服务器重复将应用程序的构建部署到未重新启动的 Tomcat 容器中),您可能会很快耗尽 JVM 中的内存。这最终会在您的 PermGen 区域中表现为 OutOfMemoryException(假设您使用的是 Sun/Oracle JVM)。有关 PermGen 的更多详细信息,请参阅 http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java

关于java - Tomcat 提示一个线程没有被停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7707254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com