---restore content starts---
1 purpose of the object combination
The combination of some existing thread-safe classes into larger components is also thread-safe;
1.1 The class that constructs the thread safety needs to consider:
All variables that make up the state of the object;
The invariant condition of the object variable (the object variable has the range of values, to ensure that the value of the variable is within this range,
Otherwise, the state of the object is invalid);
Establish the Concurrency management strategy of object State;
1.2 Categories of invariance conditions and post-condition of classes
Invariant conditions: Variables have a range of values, such as long Count,count value range is long.min_value,long.max_value,
Coupled with their own definition of count>=0;, the invariant condition of the count variable is count>=0 && count <= long.max_value;
Posterior condition: Determines whether the object from a state A to State B is valid;
1.3 Ownership of the state
The object encapsulates the state it owns, the ownership of the State, i.e. the ability to change the state, and if the object's reference is published, then the object is not the ownership of the exclusive state, and it needs to share the ownership of the state with the others;
---restore content ends---
1 purpose of the object combination
The combination of some existing thread-safe classes into larger components is also thread-safe;
1.1 The class that constructs the thread safety needs to consider:
All variables that make up the state of the object;
The invariant condition of the object variable (the object variable has the range of values, to ensure that the value of the variable is within this range,
Otherwise, the state of the object is invalid);
Establish the Concurrency management strategy of object State;
1.2 Categories of invariance conditions and post-condition of classes
Invariant conditions: Variables have a range of values, such as long Count,count value range is long.min_value,long.max_value,
Coupled with their own definition of count>=0;, the invariant condition of the count variable is count>=0 && count <= long.max_value;
Posterior condition: Determines whether the object from a state A to State B is valid;
1.3 Ownership of the state
The object encapsulates its state, owning the state ownership, which is the ability to change the state, and if the object's reference is published, it is not the ownership of the object's exclusive state, but the ownership of the shared state with the other;
2. Instance closure
Object A is enclosed in another object B, and the path to access object A is known to facilitate thread safety, and if the data is enclosed in an object, access to the data is done through methods, making it easier to ensure that the correct lock is taken when concurrency occurs;
Combination of objects in Java Concurrency programming practice