【问题标题】:how to identify java code where a thread is started when we have thread name in application log当我们在应用程序日志中有线程名称时,如何识别启动线程的java代码
【发布时间】:2014-03-17 23:53:27
【问题描述】:

我正在登录旧应用程序,我尝试使用 .setName 进行搜索,因为我们使用 thread.setName 方法设置线程名称但看不到它。我怀疑它是由应用程序启动的,我正在搜索所有 .java 文件。

Jan 30, 2014 1:00:29 AM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: The web application [/MyWebApp] appears
to have started a thread named [Control] but has failed to stop it.
This is very likely to create a mem ory leak. Jan 30, 2014 1:00:29 AM
org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyWebApp] appears to have started a
thread named [MultiThreadedHttpConnectionManager cleanup] but has
failed to stop it.

无法理解这些线程(Control 和 MultiThreadedHttpConnectionManager)从哪里开始,因此我可以修改代码来停止这些线程。

编辑:我的同事回答了其中的一部分,MultiThreadedHttpConnectionManager 在 Axis2 中是 BUG

当我在调试模式下运行 tomcat 时,我看到一些守护线程和另外两个线程(主线程、控制线程)。控制线程的命令行参数显示“org.apache.catalina.startup.Bootstrap start”。看起来 tomcat 正在启动这个线程,但是如果是这种情况,为什么 tomcat 会为此提供错误日志?

【问题讨论】:

  • 线程名称可以在setName方法中设置或者使用线程构造函数参见docs.oracle.com/javase/7/docs/api/java/lang/…
  • @SajanChandran 我同意你的观点,但我需要找出方法来识别启动该线程的代码或类名
  • 尝试通过[dependency name] control thread 扫描您的依赖项和谷歌。这可能会给你一些见解
  • @Vipin 在你的 Eclipse 中搜索 new Thread(
  • @SajanChandran 没有运气使用这个:(

标签: java multithreading tomcat6


【解决方案1】:

如果您的线程通过ThreadPoolExecutor::runWorker 运行,您可以在task.run() 上放置一个条件断点,条件为wt.name.equals("my-thread-name"),然后单步执行创建线程的代码。

【讨论】:

    【解决方案2】:

    我得到了这个问题的答案和 2 个简单的解决方案

    1. 使用 Kill -QUIT pid 获取线程转储并查看堆栈跟踪,它 给出堆栈跟踪并告诉确切的可运行/线程类 名字是。
    2. 另一个选项是在 Eclipse 中启动应用程序,请参阅 get 来自调试模式的信息。我们可以在哪里看到所有线程是什么 正在运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-01
      • 2021-08-02
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 2011-08-20
      相关资源
      最近更新 更多