K
Knute Johnson
Say I have a class that holds some data fields. I access an instance of
this class from two or more threads. In these threads I assign new
values to the fields of this class and I read some element values as
well. I know that I won't ever have simultaneous access of the elements
of the class. But since one thread may change the values of the
elements I need to prevent any memory inconsistencies. Can I do that by
making the reference to the class volatile? Or do I need to synchronize
all access to my data class?
Does making a reference variable volatile do the same thing as making a
long or a short volatile?
Thanks very much,
this class from two or more threads. In these threads I assign new
values to the fields of this class and I read some element values as
well. I know that I won't ever have simultaneous access of the elements
of the class. But since one thread may change the values of the
elements I need to prevent any memory inconsistencies. Can I do that by
making the reference to the class volatile? Or do I need to synchronize
all access to my data class?
Does making a reference variable volatile do the same thing as making a
long or a short volatile?
Thanks very much,