Skip to content
Advertisement

Tag: happens-before

Thread-safety of int field in Java

If class has field with int type (not Atomic Integer and without volatile keyword) and all access to this field happens under read/write locks – will this field thread-safe in this case? Or in some moment some thread can see not real value of this field but something from cache? Answer Get answer from @pveentjer in comments under question: It

Java happens-before relationship?

Consider the following code. Thread A calls run(), then another thread B calls test() and there shouldn’t be any happens-before relationship. I know it is not guaranteed that thread B sees the changes which thread A made. But is it possible that the output of this program is: Answer Yes, it’s possible, because it’s not explicitly forbidden. The read of

Advertisement