Are static variables shared between threads?

There isn’t anything special about static variables when it comes to visibility. If they are accessible any thread can get at them, so you’re more likely to see concurrency problems because they’re more exposed. There is a visibility issue imposed by the JVM’s memory model. Here’s an article talking about the memory model and how … Read more

Why does this Java program terminate despite that apparently it shouldn’t (and didn’t)?

Obviously the write to currentPos doesn’t happen-before the read of it, but I don’t see how that can be the issue. currentPos = new Point(currentPos.x+1, currentPos.y+1); does a few things, including writing default values to x and y (0) and then writing their initial values in the constructor. Since your object is not safely published … Read more