简体   繁体   English

在Eclipse中调用Thread.run()的层次结构

[英]Call hierarchy of Thread.run() in Eclipse

I tend to use eclipse's "Open Call Hierarchy" function a lot, to trace where method calls are going in larger Java projects. 我倾向于大量使用eclipse的“ Open Call Hierarchy”功能来跟踪方法调用在大型Java项目中的去向。 I get irritated by Threads, as the call hierarchy shows the callers of the Thread.run() method as various internal Java threading functions, rather than the Thread.start() call which effectively led to the thread being run. 我被Threads激怒了,因为调用层次结构将Thread.run()方法的调用者显示为各种内部Java线程函数,而不是Thread.start()调用,后者实际上导致了线程的运行。

Is there any way to make Eclipse show the Thread.start calls as the parent of Thread.run() methods. 有什么方法可以使Eclipse将Thread.start调用显示为Thread.run()方法的父Thread.run() Perhaps a plugin to do this? 也许有插件可以做到这一点?

If I understand you're question: you want to find the caller of the Thread.start() method for a given Runnable.run() method? 如果我理解您的问题,那么您想为给定的Runnable.run()方法找到Thread.start()方法的调用者吗?

I find that this would be useful for very small, short running anonymous Runnables. 我发现这对于非常小的短期运行的匿名Runnables很有用。

However, in the more general case, I'm not sure of further practicality: 但是,在更一般的情况下,我不确定是否进一步实用:

  • Standard practice is that a Runnable is passed into a Thread as a constructor argument. 标准做法是将Runnable作为构造函数参数传递给Thread。 It is frequently the case that Runnable is called by a pre-constructed Thread (eg Executors, asynchExec). 通常,通过预先构造的线程(例如Executors,asynchExec)调用Runnable。 In this case, it is the callers of the constructor you are interested in. 在这种情况下,它就是您感兴趣的构造函数的调用者。
  • Non-anonymous Runnables will may be traced back via its constructor (call hierarchy on that ctor would be a good approach) 非匿名Runnable可能会通过其构造函数进行追溯(该ctor上的调用层次结构将是一个好方法)
  • An override of the Thread.run() method may do it, but then you're more interested in the Thread.start() method's callers 可以重写Thread.run()方法,但是您对Thread.start()方法的调用者更感兴趣
  • The call hierarchy view is (AFAIK) not very extensible (however, Implementors used to do this, but was written by the same people as the original call hierarchy before it was intergrated into the core JDT). 调用层次结构视图(AFAIK)并不是很可扩展(但是, 实现者曾经这样做,但是在将其集成到核心JDT中之前,它是由与原始调用层次结构相同的人编写的)。

Interesting question. 有趣的问题。

You are welcome to check out nWire . 欢迎您查看nWire It's a new tool for exploring all the associations of your code in one dynamic view. 这是一个用于在一个动态视图中浏览代码的所有关联的新工具。 Very convenient and simple to use. 非常方便和易于使用。 It combines the callers and implementors (and all other associations) together. 它将调用者和实现者(以及所有其他关联)组合在一起。 Would love to have your feedback on it. 希望收到您的反馈。

Thanks for your response Jamesh. 感谢您的回答,詹姆士。 With the first two points you made, you say that (in both anonymous and non-anonymous Runnables)it would be useful to look at the call hierarchy of the Runnable's constructor - yes, I agree! 在前面两点中,您说(在匿名和非匿名Runnable中)查看Runnable构造函数的调用层次结构将很有用-是的,我同意! This is usually what I end up doing. 这通常是我最终要做的。 But it usually means frequent switching between the two hierarchies, only one of which can be shown at a time. 但这通常意味着在两个层次结构之间频繁切换,一次只能显示其中一个。 I would like to avoid this by retaining one hierarchy. 我想通过保留一个层次结构来避免这种情况。

There is no direct call hierarchy between the Runnable constructor and the call to run(), so it seems to me that it would be inappropriate to extend the call hierarchy by adding the constructor as a "caller" of run(). 在Runnable构造函数和对run()的调用之间没有直接的调用层次结构,因此在我看来,通过将构造函数添加为run()的“调用方”来扩展调用层次结构是不合适的。 However, calls to start() or to add the thread to an Executor (or perhaps run() calls within the executor) might be appropriate to show in the call hierarchy. 但是,调用start()或将线程添加到执行程序(或执行程序内的run()调用)可能适合在调用层次结构中显示。

I really was just wondering if there was an existing solution to this which I was unable to find. 我真的只是想知道是否存在无法解决的现有解决方案。 I guess I'll just have to make an attempt at a plugin myself if I want it enough. 我想如果我想要足够的话,我只需要自己尝试一个插件即可。

I tried out the implementors plugin. 我尝试了实现者插件。 It is useful, but not for this particular problem! 这很有用,但不适用于此特定问题!

I also tried out nWire. 我也尝试了nWire。 It has a lot of features which I haven't had time to explore fully, but I couldn't find a way to do what I'm looking for here. 它有很多功能,我还没有时间去充分研究,但是我找不到在这里寻求解决方案的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM