volatile and caches question

Winnie JayClay winniejayclay at gmail.com
Wed Jul 23 13:05:38 UTC 2014


Hi,

Say, if I have class with volatile variable, but only one thread operates
on that variable (read and update it), will be memory flushed always on x86
when the same thread read and write? What is the overhead and do you have
any optimizations in JDK? Also if I have multiply threads which operate on
single volatile variable: one writer and many readers and writer doesn't
write too much, will be caches flushed every time readers access volatile
varible and when write didn't write anything? I also thought to use normal
non-final non-volatile variable and for writer thread create and invoke
synchronized block somwhere after it will update varible to establish
happens-before, i.e. just a synchronized block to flush caches for reader
threads to pick up the latest value - by the way, is my understanding
correct that if writer somewhere else invokes synchronized block which is
not available for readers, will the readers get the latest value?

Thanks for help, we work on HFT project in java, and performance is
super-critical for us.


Thanks,
Winnie


More information about the hotspot-dev mailing list