Chapter 05 - Summary

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