Is the next Safe kernel in java?
public class TestDCL{ private static final Semaphore lock = new Semaphore(1); private Object instance; public Object m(){ if(instance == null){ lock.acquire(); if(instance == null){ instance = new Object(); } lock.release(); } return instance; } }
: . instance ? instance , volatile. , , , @Vijay Mathew, - . , singleton , . volatile , , .
instance
volatile
Java Concurrency , 16.2.3 . 16.2.4 .
. new Object(); . instance null, . , if instance, . , Bill Pugh, .
new Object();
null
if
Tim. , , , ( -/JVM).
, , . ? , , , intialisation - , .
, . , ? , , syncronization per-sa. DCL .
Source: https://habr.com/ru/post/1772597/More articles:Скопировать данные из указателя? - pointershttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1772593/conventional-usage-of-this-in-java-class-to-refer-to-an-instance-variable&usg=ALkJrhhR2EZFVYHGd7U71GXr0_keR0jVUAflex builder 4 unknown error in xml file? - xmljavascript array_pop - javascriptScreen saver is not displayed - androidShould I use a lot of ClearCase views? Is this recommended? - clearcasewhat is the way to find if an array contains an arithmetic progression (sequence) - arraysPython mechanism with dynamic drop-down list - pythonjava collection slow conversion - javaTime counter - linuxAll Articles