java - How do I deep copy an irregular 2D array threadsafely -


I stumbled over an annoyance because I was writing a Java class; I could not understand how to copy a 2 dimensional array thread safely, it is a simple version of the class:

  public class frames {private boolean [] [] content; Public frame (boolean [] [] content) {boolean [] [] thread sophie cappoie = deep copy (content); If (! (Thread sap copy! = Null)) {new tap pointer exception ("content should not be empty"); } If ((Thread SAPPP lamp & gt; 0)) (Setting new invalid records exception ("content.length should be greater than 0");} If (! (Thread! SAPPPP [0]! = Null)! (To remove new illegal execution ("The content [0] should not be blank");} If (thread (SAGPP (0) length of gt; 0)) (new material adoption invalid ("content [0] length. Should be greater than 0 ");} (int i = 1, count = threadSafeCopy.length; i  private boolean [] [] deep code (boolean [] [] content) is not really the thread.  That the array is actively being modified by another thread, while this method is trying to copy. It has been assumed that I have guarded against the most insulting case, using  synchronized  based on the base code. However, this second dimension array does not give reason to lock the set of examples. And it is possible for them to be modified during the copy.  

Is there a way to collect object lock for each basic array ( content ) and sub-arrays ( content [0] , Content [1] , ..., content [content.length - 1] ) I can call something like synchronize (objectTalk system-loan) And it locks all the items together and in the order of the list. If so, I can safely copy the contents of the array.

If not, what other types of solutions are available for "block all other modifications in the array" without changing the categories of frames exchanging? Or changing the constructor of the frame as if it will not take an array, but only examples of the immutable collection (which is itself below another strange Rabbit hole)

Thank you for any guidance you have in this field. / P>

Update: What I want to do is not fundamentally possible. And my understanding of locking synchronized objects was erased (Timm Glockoder, Paulo and Brian). I now have the interface on the frame to the list & lt; List & lt; Boolean & gt; & Gt; I'm going to change to use , which, of course, looks like it is too much incompetence or I set & lt; XyCoordinate & gt; where the presence of a XyCoordinate means "true" again, it seems that it is so weirdly disabled, but the thread. Oh, is that so! I think your best bet is to wrap the object in an object and give it synchronized access. Then you can do the Gori copy with "door shut" in the accelerator method.

  zero-depth copy (boolean [] [] orig) {synchronize (original) {boolean [] [] results = new boolean [orig.length] []; DeepCopy (original, 0); Return result; }} / ** * Copy the recursive method to lock all the rows in an array, and then copy them * behind (by chance) * / zero deep copy (boolean [] [] orig, int row {if ( Row == orig length) Return; // Lock the end position (orig [row]) {// lock the first deep copy (original, line + 1); // Lock next line content [row] = new bullion [original [row]. Length]; For (int i = 0; i & lt; content [line] length; i ++) content [row] [i] = original [row] [i]; // now, do line - 1}}    

Comments