lundi 23 février 2015

Taking 'snapshots' of big Objects



I'm facing the following issue. One Thread is building and updating a Tree Object. To validate the Tree it is required to calculate the hash of that tree. So a second Thread calculates the hash of that tree continuously.


Now I got the following problem: That tree is about 300mb in size and I wanna ensure that the Tree doesn't change while the hash is calculated, like taking a snapshot and calculate the hash of it.


My guess is I have the following two options:



  1. Blocking writing to the Tree while the hash is calculated. (not ideal, because the calculations takes quite some time)

  2. Taking a 'snapshot' by copying that object. And then calculate the hash. (also not very good because another 300mb of memory would be required)


Is there a common trick or a pattern for taking 'snapshots' of big objects without just copying them?


(My guess is that this takes profounded changes to the tree object, but I'm grateful for every tip.)


Thanks in advance, flxh


PS: I don't know if it matters for that question but I am using Java (1.8)




Aucun commentaire:

Enregistrer un commentaire