Proper use of volatile variables and synchronized blocks
问题 I am trying to wrap my head around thread safety in java (or in general). I have this class (which I hope complies with the definition of a POJO) which also needs to be compatible with JPA providers: public class SomeClass { private Object timestampLock = new Object(); // are "volatile"s necessary? private volatile java.sql.Timestamp timestamp; private volatile String timestampTimeZoneName; private volatile BigDecimal someValue; public ZonedDateTime getTimestamp() { // is synchronisation