Race conditions occur only of multiple threads are accessing the same resource and one or more of these threads write to the resource. Immutable objects shared between threads cannot be changed, and thereby thread safe. ``` public class ImmutableValue{ private int value = 0; public ImmutableValue(int value){ this.value = value; } public int getValue(){ return this.value; } } ``` ImmutableValue instances are passed an initial value through the constructor and do not have setter method that can change the value. Once an ImmutableValue instance is created you cannot change its value. It is immutable. You can read it however, using the `getValue()` method. If you need to perform operations on the ImmutableValue instance you can do so by returning a new instance with the value resulting from the operation. ``` public class ImmutableValue{ private int value = 0; public ImmutableValue(int value){ this.value = value; } public int getValue(){ return this.value; } **public ImmutableValue add(int valueToAdd){ return new ImmutableValue(this.value + valueToAdd); }** } ``` # The Reference is not Thread Safe ``` public class Calculator{ private ImmutableValue currentValue = null; public ImmutableValue getValue(){ return currentValue; } public void setValue(ImmutableValue newValue){ this.currentValue = newValue; } public void add(int newValue){ this.currentValue = this.currentValue.add(newValue); } } ``` The `Calculator` class holds a reference to an `ImmutableValue` instance. Notice how it is possible to change that reference through both the `setValue()` and `add()` methods. Therefore, even if the `Calculator` class uses an immutable object internally, it is not itself immutable, and therefore not thread safe. In other words: The `ImmutableValue` class is thread safe, but the **use of it** is not. This is something to keep in mind when trying to achieve thread safety through immutability. To make the `Calculator` class thread safe you could have declared the `getValue()`, `setValue()`, and `add()` methods `synchronized`. That would have done the trick.