사용자 도구

사이트 도구


java:lazy_evaluation

문서의 이전 판입니다!


Java Lazy Evaluation

Effective Java 3rd Item 83 - double check

    // Double-check idiom for lazy initialization of instance fields - Page 334
    private volatile FieldType field4;
 
    // NOTE: The code for this method in the first printing had a serious error (see errata for details)!
    private FieldType getField4() {
        FieldType result = field4;
        if (result != null) // First check (no locking)
            return result;
 
        synchronized(this) {
            if (field4 == null) // Second check (with locking)
                field4 = computeFieldValue();
            return field4;
        }
    }
java/lazy_evaluation.1589791309.txt.gz · 마지막으로 수정됨: 2020/05/18 17:41 저자 kwon37xi