Chapter 05 - Summary
- Use
finalfield unless they need to be mutable- Reduce the possible actiosn to mutate the field
- Encapsulation the data
- Dont use global variable, share the state within the thread/object. Use exchange if necessary
- Guard each mutable variable with
lock - Guard all variables in an invariant (related to each other) with
lock - Hold locks for the duration of the compound action
- Document your thread safety using
@ThreadSafe,@NotThreadSafe@GuardedBy