• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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

 
Ranch Hand
Posts: 48
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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

 
Marshal
Posts: 67256
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42974
76
  • Mark post as helpful
  • send pies
  • 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.
 
Marshal
Posts: 13441
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21716
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!