I have an object which is used by multiple threads, but never concurrently (always only one thread executes a method on it). It contains several non-final fields. Now I am wondering whether I have to mark all fields as volatile to ensure that the next thread (which might have used the object before) will see the changes. Without volatile, at what point does a thread pick up changes from another thread? Are there any guarantees?
If I have to use volatile, how does Akka solve this problem?
Behind the scenes Akka will run sets of actors on sets of real threads, where typically many actors share one thread, and subsequent invocations of one actor may end up being processed on different threads. Akka ensures that this implementation detail does not affect the single-threadedness of handling the actor’s state.