The Java memory model makes it clear what can and cannot be assumed about how threads interact through memory. For example, if one thread writes a new value to a field without appropriate synchronization then the new value is not guaranteed to be observable by other threads. In practice, however, other threads might anyhow read the new value in spite of inadequate synchronization, depending on time between write and read, hardware architecture, etc.
This can lead to bugs that are hard to discover and difficult to reproduce. It could therefore be useful to run a java application on a worst case JVM that did absolutely no memory synchronization between threads beyond the guarantees in the Java memory model. Does such a worst case JVM implementation exist?
You could try using Terracotta to cluster your program. It is incredibly unforgiving around incorrect synchronization (which will become apparent even with only one node in the cluster). This is a great question: I've often wanted exactly this ability - I'm surprised there's not a switch in the standard JRE -XXJMMExtreme
Terracotta is open-source and free for the basic product.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With