在Java应用程序中查找线程创建源 [英] Finding Source of Thread Creation in a Java application

查看:117
本文介绍了在Java应用程序中查找线程创建源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个有线程问题的Java应用程序。

I am working on a Java application which has a threading issue.

在附加Netbeans Profiler的情况下使用应用程序一段时间后,我可以看到创建了几个线程。他们中的大多数都以 .5秒结束。我只能找到应用程序中使用的SwingWorkers。

While using the applications for some time with Netbeans profiler attached, I can see several threads are created. Most of them finish in some .5 seconds. I could only find SwingWorkers used in the application.

此外,探查器显示的大多数线程是普通线程而不是SwingWorkers。除非这些线程是间接由SwingWorker创建的,我怀疑,应用程序使用的某些库正在创建它们。

Moreover, the majority of threads displayed by the profiler are normal threads and not SwingWorkers. Unless these threads were created by SwingWorker indirectly, I suspect, some library that the application uses is creating them.

现在我想删除此问题。但我找不到确定线程创建源的方法。如果你能建议一些其他的探查器/工具,我可以通过它找到线程创建的源(方法)。

Now I would like to remove this issue. But I could not find a way to determine the source of thread creation. If you can please suggest some other profiler/tool by means of which I can find the source(method) of thread creation.

推荐答案

如果使用Eclipse及其调试器是一个选项,您可以尝试以下方法:

If using Eclipse and its debugger is an option, you might try the following:


  • 将代码导入一个Java项目。

  • Ctrl-Shift-T(打开类型),输入Thread。将打开Thread类的二进制源编辑器。

  • 在Outline视图中选择所有Thread构造函数,使用上下文菜单Toggle Method Breakpoint。这为构造函数创建了断点。

  • 运行和调试。

  • Import the code into a Java project.
  • Ctrl-Shift-T (Open Type), enter "Thread". The binary source editor for the Thread class opens.
  • Select all the Thread constructors in the Outline view, use context menu "Toggle Method Breakpoint". That creates breakpoints for the constructors.
  • Run and debug.

或者

您可以获得 Yourkit Java Profiler ,它也适用于评价。它可以显示在应用程序中创建的线程,包括它们的堆栈跟踪(也在线程完成之后)。它没有显示创建线程的位置,但线程的堆栈跟踪可能会为您提供有关所涉及库的一些线索。

You could get the Yourkit Java profiler, which is also available for evaluation. It can show the threads created in an application including their stack traces (also after the thread finished). It does not show where the threads were created, but the stack trace of the threads might give you some clues about the involved libraries.

这篇关于在Java应用程序中查找线程创建源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆