views:

622

answers:

4

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.

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?

A: 

If I understand you're question: you want to find the caller of the Thread.start() method for a given Runnable.run() method?

I find that this would be useful for very small, short running anonymous 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.
  • Non-anonymous Runnables will may be traced back via its constructor (call hierarchy on that ctor would be a good approach)
  • An override of the Thread.run() method may do it, but then you're more interested in the Thread.start() method's callers
  • 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).
jamesh
A: 

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.

zvikico
A: 

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.

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.

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.

A: 

here is how try that in VS2010.

http://blog.flair-systems.com/2010/05/c-fastfood-call-hierarchy-of-methods.html

Waleed Mohamed