Professional Documents
Culture Documents
Classes intended to be shared between threads can be made immutable, i.e., instance of the class cannot be updated (or state cannot be changed) once they are
created which ensures thread-safety. Example:
~Note: Class is made immutable above - i. the class is final ii. no setters, final member variable iii. an operation like add here, results in creating a new instance
of the class ~
Even if the class itself is immutable and thereby thread-safe, a reference to this object may NOT be thread-safe. Example:
The class LeakyReference is not immutable even though it uses an immutable object, hence not thread-safe. It has mutator methods that can change the reference
of the instance of ImmutableValue .
== End of section ==