Call trace in java

前端 未结 8 2168
野趣味
野趣味 2020-12-05 11:38

Is there a way to output a call trace for a particular thread in java?

I do not want a stack trace. I would like a sequence of calls on each object for tracing.

8条回答
  •  遥遥无期
    2020-12-05 11:58

    We could create a new Throwable object which will have the call trace. And using some string manipulations, we can get the call stack.

    Throwable t = new Throwable();
    System.out.println(t.getStackTrace()[1].toString());
    

    I'm not sure retrieving the info this way , is a good practice or not. :)

提交回复
热议问题