We have a requirement where we would like to retrieve Calling Class name(with Package structure)and use it inside the called class.
I have searched and found out two ways ...
1) String callingClassName = new Throwable().fillInStackTrace().getStackTrace().getClassName();
2) String callingClassName =
but these two approaches pose performance issue as both take arround 15-16 millisecond to execute, which is not acceptable in large application.
Any other suggestions or enhancement to above two approaches would be highly appreciated.
Hi, I dont think u can do without using reflection unless u main a call trace programmatically which will have a memory foot print. So choose one of them
Thanx and Regards
I was thinking of using a static ThreadLocal variable and setting a unique value to it in the application's main thread.
then accessing the same in my class where ever i would like to distinguish calling threads and control my flow.
I tried this approach now and its working fine.