• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is there are any way to identify the place from where the particulate method is calling in runtime?

 
Ranch Hand
Posts: 48
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Is there are any way to identify the place from where the particulate method is calling in runtime?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? If the method needs information to make decisions, such info should be passed explicitly as a parameter; not implicitly based upon where it was called from.
 
Varun Selva
Ranch Hand
Posts: 48
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why? If the method needs information to make decisions, such info should be passed explicitly as a parameter; not implicitly based upon where it was called from.




I am asking this for inquiry purpose.
because I have to find from existing flow in a complex Project.

I can make sure that,that method is called by somewhere. But couldn't find the place.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this is possible, and I'll disagree with Bear that it's always feasible to pass the necessary information to the method.

At the spot where you need this information, start with StackTraceElement[] stackTrace = (new Exception()).getStackTrace() and examine what's in that array.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of other options for this kind of investigation. You could use an IDE like Eclipse to find all the references to that method. This method assumes that you have the source code and you are only interested in calls made to the method from within the immediate project or workspace codebase. If there is calling code for which you don't have the source, you could set a breakpoint inside that method and run the program in a debugger, then examine the call stack every time you hit the breakpoint.
 
Rancher
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:At the spot where you need this information, start with StackTraceElement[] stackTrace = (new Exception()).getStackTrace() and examine what's in that array.


Or, to avoid having to create an Exception object
Thread.currentThread().getStackTrace()
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still might. From the source of Java 6 through 8:
dumpThreads is native, but if getStackTrace() is called on the current thread it just creates a new exception.

However, I must agree that Thread.currentThread().getStackTrace() looks cleaner.
 
reply
    Bookmark Topic Watch Topic
  • New Topic