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

can someone suggest some solution. If I want to get the name of the calling class of the thread start method.

for example, if I start the stream mainly, the stack trace gives the name of the call class as the name of the stream and the name of the caller as started for index 2. Please help find the correct class names of the caller and the name of the stream method.

+5
source share
1 answer

It sounds like you're trying to bundle tasks that span multiple threads. The best thing you can do if you start the stream directly is to give it a name in the constructor, then put the name of the calling class and the method name along with the new stream name. But this will not work if you use ExecutorService.

More generally, you should investigate using the nested diagnostic context so that you can associate multithreaded operations: Logging in multithreaded applications

+1
source

All Articles