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

时间:2023-01-14 12:04:03

I tend to use eclipse's "Open Call Hierarchy" function a lot, to trace where method calls are going in larger Java projects. 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.

我倾向于使用eclipse的“Open Call Hierarchy”函数来跟踪大型Java项目中方法调用的位置。我对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. Perhaps a plugin to do this?

有没有办法让Eclipse将Thread.start调用显示为Thread.run()方法的父级。也许是一个插件来做到这一点?

3 个解决方案

#1


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. It is frequently the case that Runnable is called by a pre-constructed Thread (e.g. Executors, asynchExec). In this case, it is the callers of the constructor you are interested in.
  • 标准做法是将Runnable作为构造函数参数传递给Thread。通常情况是Runnable由预先构造的Thread调用(例如Executors,asynchExec)。在这种情况下,它是您感兴趣的构造函数的调用者。

  • Non-anonymous Runnables will may be traced back via its constructor (call hierarchy on that ctor would be a good approach)
  • 可以通过其构造函数追溯非匿名Runnables(该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之前由与原始调用层次结构相同的人编写)。

#2


Interesting question.

You are welcome to check out 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.

欢迎您查看nWire。它是一种在一个动态视图中探索代码的所有关联的新工具。使用非常方便和简单。它将调用者和实现者(以及所有其他关联)组合在一起。很想得到你的反馈。

#3


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! 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.

感谢您的回复Jamesh。根据你提出的前两点,你说(在匿名和非匿名的Runnables中)查看Runnable的构造函数的调用层次结构是有用的 - 是的,我同意!这通常是我最终要做的事情。但它通常意味着在两个层次结构之间频繁切换,一次只能显示其中一个层次结构。我想通过保留一个层次结构来避免这种情况。

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(). 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.

Runnable构造函数和对run()的调用之间没有直接的调用层次结构,因此在我看来,通过将构造函数添加为run()的“调用者”来扩展调用层次结构是不合适的。但是,调用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. 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.

我也尝试过nWire。它有很多我没有时间去探索的功能,但我找不到办法在这里做我正在寻找的东西。

#1


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. It is frequently the case that Runnable is called by a pre-constructed Thread (e.g. Executors, asynchExec). In this case, it is the callers of the constructor you are interested in.
  • 标准做法是将Runnable作为构造函数参数传递给Thread。通常情况是Runnable由预先构造的Thread调用(例如Executors,asynchExec)。在这种情况下,它是您感兴趣的构造函数的调用者。

  • Non-anonymous Runnables will may be traced back via its constructor (call hierarchy on that ctor would be a good approach)
  • 可以通过其构造函数追溯非匿名Runnables(该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之前由与原始调用层次结构相同的人编写)。

#2


Interesting question.

You are welcome to check out 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.

欢迎您查看nWire。它是一种在一个动态视图中探索代码的所有关联的新工具。使用非常方便和简单。它将调用者和实现者(以及所有其他关联)组合在一起。很想得到你的反馈。

#3


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! 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.

感谢您的回复Jamesh。根据你提出的前两点,你说(在匿名和非匿名的Runnables中)查看Runnable的构造函数的调用层次结构是有用的 - 是的,我同意!这通常是我最终要做的事情。但它通常意味着在两个层次结构之间频繁切换,一次只能显示其中一个层次结构。我想通过保留一个层次结构来避免这种情况。

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(). 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.

Runnable构造函数和对run()的调用之间没有直接的调用层次结构,因此在我看来,通过将构造函数添加为run()的“调用者”来扩展调用层次结构是不合适的。但是,调用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. 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.

我也尝试过nWire。它有很多我没有时间去探索的功能,但我找不到办法在这里做我正在寻找的东西。