[JAVA concurrent programming practices] 1. Object sharing and java practices
1. Stack closures
In stack closures, objects can only be accessed through local variables.
Stack blocking refers to limiting the Declaration and Application of variables to a local thread. The declarations and instantiated objects in this local thread are invisible to the outside of the thread, the stack of this local thread cannot be accessed by any other thread.
2. immutability
Immutable objects must be thread-safe.
3. Common Security release Modes
To securely publish an object, the object reference and object state must be visible to other threads at the same time.
1. Initialize an object reference in the static initialization function.
2. Save the object reference to a volatitle-type domain or AtomicReferance object.
3. Save the object reference to the final type domain of a correctly constructed object.
4. Save the object reference to a domain protected by the lock.