In a multi-threaded environment, how can a stream see a “partially constructed object”? I realized that it is not thread safe, as multiple threads can create multiple instances.
class LazyInit { private static Resource resource = null; public static getInstance() { if (resource == null) { resource = new Resource(); } return instance; } }
Because of the record because of the order.
, , . Java , , , , , , .. Java.
, , . , , if , . , CPU, null-null, . , ., , Resource , getInstance. , singleton.
if