如何查找线程最初启动的位置 [英] How to find where a thread was originally started

查看:123
本文介绍了如何查找线程最初启动的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个应用程序可以产生多个线程,如果需要执行任务...所以没有什么特别的。我使用Eclipse编写和调试Java应用程序。一个线程(让它称之为异步任务)在离开run()方法后立即重新生成(所以有bug,我想找到这个行为的原因)。



我的问题是,如果我暂停此线程异步任务使用eclipse IDE(调试透视图)有没有办法找出这个线程最初启动的位置例如使用Debug视图或任何其他)?因为我想知道谁生产这个线程(没有进行文本搜索或这样的东西)。



有没有一个很好的方式来获取这些信息?

解决方案

我将在 Thread.start()中设置断点,并启用条件





每当一个名为异步任务的线程启动时,条件都将被计算为true,调用start方法的线程将被暂停。然后你可以看到stacktrace从哪里来电。


Supposed I have an application that can spawn multiple threads if needed for doing tasks ... so nothing special. I use Eclipse to write and debug Java applications. A thread (lets call it "async task") is immediatly respawned after it leaves the run() method (so there is bug and I want to find the reason for this behavior).

My question, if I pause this thread "async task" using the eclipse IDE (debug perspective ..) is there way to find out where this thread was originally started (for example using the Debug view or any other)? Because I want to know who spawns this thread (without making a text search or something like this).

Is there a good way to get this information?

解决方案

I would set a breakpoint at Thread.start() and enable a condition

Whenever a thread named "async task" is started the condition is evaluated to true and the thread that invokes the start method is paused. Then you can see in the stacktrace from where the call came.

这篇关于如何查找线程最初启动的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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