Graciela the behavior that you are seeing is due to the integer constant pool that
java maintains. When an int is boxed into Integer, and its in the range of -128 to 127, then the Integer object is taken from that pool. This is defined in the
JLS
If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.
So you have three instances of
Letter2 class which all have the same instances of
first and
redlight. That's why synchronization works on them but not on
this. Try to modify your code in one of the following manners
OR
Both the above codes will work similar to
this now i.e. the synchronization will not work...