A thread-safe holder for arbitrary cloneable data
问题 I have a class SomeMutableData with a public clone() method. I want to make sure, that no thread ever sees an inconsistent state (assuming the instances will be passed around using the holder only). I assume using synchronization is the safest possibility, right? public final class ThreadSafeHolder { public ThreadSafeHolder(SomeMutableData data) { storeData(data); } public synchronized SomeMutableData cloneData() { return data.clone(); } public synchronized void storeData(SomeMutableData data