In Java can I depend on reference assignment being atomic to implement copy on write?
问题 If I have an unsynchronized java collection in a multithreaded environment, and I don't want to force readers of the collection to synchronize [1] , is a solution where I synchronize the writers and use the atomicity of reference assignment feasible? Something like: private Collection global = new HashSet(); // start threading after this void allUpdatesGoThroughHere(Object exampleOperand) { // My hypothesis is that this prevents operations in the block being re-ordered synchronized(global) {