The project uses Ehcache as a buffer between the program and the database, the cache object is modified during use, such as Plan.setlangsymbol (), where the cache is used, and the data taken is modified, so the guess is caused by a shallow reference to the cache.
In fact, StackOverflow also mentions this issueCache.get () returns deep copy of element? 》
As for how to do deep Copy,stackoverflow also mentions theCopying cached map<string, list> object into temporary map<string, List> ; Object, after experimentation, confirms that guava's Maps.newhashmap (MAP) Tool class method is also shallow copy.
One way is to iterate over the contents of the object, assigning each property to a new, rebuilt object.
In addition, there is a simpler way, "A Java deep Clone" example uses the object serialization characteristics to complete, see the following code:
/*** This method makes a ' deep clone ' of any object it is given. */ Public StaticObject Deepclone (Object object) {Try{bytearrayoutputstream BAOs=NewBytearrayoutputstream (); ObjectOutputStream Oos=NewObjectOutputStream (BAOs); Oos.writeobject (object); Bytearrayinputstream Bais=NewBytearrayinputstream (Baos.tobytearray ()); ObjectInputStream Ois=NewObjectInputStream (Bais); returnOis.readobject (); } Catch(Exception e) {e.printstacktrace (); return NULL; } }} /*** These classes implement Serializable so we can write them out and * read them back in as a stream of bytes.*/classPersonImplementsSerializable {String firstName, lastName; Address address; PublicPerson (String firstName, String lastName, address address) { This. FirstName =FirstName; This. LastName =LastName; This. Address =address; } PublicString toString () {StringBuilder sb=NewStringBuilder (); Sb.append ("First Name:" + firstName + "\ n"); Sb.append ("Last Name:" + lastName + "\ n"); Sb.append ("Street:" + address.street + "\ n"); returnsb.tostring (); }}
Very simple!
References to Ehcache content and deep copy of Java