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记录栈信息,即以独占锁的形式操作,故非常耗时。

  

posted @ 2018-06-22 09:41  miss小张  阅读(494)  评论(0编辑  收藏  举报