Could not understand methods 1 and 3 as to how it helps to achieve safe publication. Can anyone help me understand this with an example if possible.
To publish an object safely, both the reference to the object and the object's state must be made visible to other threads at the same time. A properly constructed object can be safely published by:
Initializing an object reference from a static initializer
Storing a reference to it into a volatile field or AtomicReference
Storing a reference to it into a final field of a properly constructed object
Storing a reference to it into a field that is properly guarded by a
lock.