Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the calling class name of a Thread's start method using stacktrace

Tags:

java

swing

can somebody kindly suggest some solution In case I want to get the calling class name of a thread's start method

for example if I start a thread in main the stack trace gives calling class name as thread and caller method name as run for index 2. please help in finding the correct names of the caller class and method name of a thread.

like image 260
Sanyam Goel Avatar asked Apr 26 '12 10:04

Sanyam Goel


1 Answers

Looks like you're trying to tie up tasks that span multiple threads. About the best you can do if you're starting a thread directly is to give it a name in the constructor, then log the calling class and method name along with the new thread's name. But this won't work if you use an ExecutorService.

More generally you should investigate using Nested Diagnostic Context to allow you to tie up multi-threaded operations: Logging activities in multithreaded applications

like image 170
artbristol Avatar answered Oct 26 '22 18:10

artbristol