How Expensive is Thread.getStackTrace()?

后端 未结 4 1858
悲哀的现实
悲哀的现实 2020-12-05 05:34

In a logging system, every log output is done by a helper class with a method such as this one

public void debug(String message) {
    Logger logger = Logge         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 06:17

    From what I recall, there's some impact in using Thread.getStackTrace() - especially with large stacks (such as when using in server-side or J2EE situations). You could try Throwable.getStackTrace() for better performance.

    At any rate, calling those functions regularly (as opposed to doing so in an exception situation) will impact your app.

提交回复
热议问题