문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 다음 판 | 이전 판 | ||
|
java:lazy_evaluation [2020/05/18 17:15] kwon37xi 만듦 |
java:lazy_evaluation [2020/05/19 09:28] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 4: | 줄 4: | ||
| * [[https:// | * [[https:// | ||
| * [[java: | * [[java: | ||
| + | * [[https:// | ||
| + | |||
| + | ===== Effective Java 3rd Item 83 - double check ===== | ||
| + | * https:// | ||
| + | * [[https:// | ||
| + | <code java> | ||
| + | // 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; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||