Full volatile Visibility Guarantee

The only guarantee that this code can give you, is that if a certain thread observes the value written to days, it will also observe the values written to years and months - if there were no update calls again; these are not atomic.


It's all about happens-before relationship.

This relationship is simply a guarantee that memory writes by one specific statement are visible to another specific statement.

  1. In the same thread,

        this.years  = years;
        this.months = months;
    

    happens-before:

        this.days   = days;
    
  2. In different thread, the write of volatile variable happens-before the reader thread which read the volatile variable.

And, happens-before relationship has transitivity. When the reader thread see the fresh value of volatile variable days, it can also read the fresh value of years and months.