java异常耗时原因

首先看源码 :

    public synchronized Throwable fillInStackTrace() {
        if (stackTrace != null ||
            backtrace != null /* Out of protocol state */ ) {
            fillInStackTrace(0);
            stackTrace = UNASSIGNED_STACK;
        }
        return this;
    }

    private native Throwable fillInStackTrace(int dummy);

原因: 发现在生成异常时fillInStackTrace方法使用了synchronized记录栈信息,即以独占锁的形式操作,故非常耗时。

  

猜你喜欢

转载自www.cnblogs.com/xiaotong1223/p/9211954.html