Let's consider this piece of code:
class Foo {
//Possibly any other immutable type
static Instant ins = Instant.now();
static void thread1() {
while(true) System.out.println(ins.toString());
}
static void thread2() {
while(true) ins=Instant.now();
}
}
(Assuming thread1 and thread2 are run in different threads)
Can this result in any undefined behaviour or crash directly?
Can, at any point, have thread1 reference to invalid object? (invalid meaning incomplete or null, not "old")
Will any value from thread2 be "flushed" from the cache at some point?