title: Java: how to synchronize array accesses and what are the limitations on what goes in a synchronized condition
body: <p>I had a 2x2 array that I had two threads operating on.</p>
  
  <p>it is possible to use a synchronized statement in java on an array?</p>
  
  <p>how does the locking work? the java tutorial thread said that the synchronized statement works on objects, so I wasn't sure what they meant. Another site said that I could make a statement like</p>
  
  <pre><code>synchronized (array1[]){
  
  }
  </code></pre>
  
  <p>Does this synchronize accesses to everything in the array so that the array is locked to other threads?</p>
  
  <p>if I have a two-d Array can i use</p>
  
  <p><code>synchronized (array1[i])</code> to lock one of the rows of the array?</p>
  
  <p>and is it possible to lock individual array values
  with something like</p>
  
  <pre><code>synchronized (array1[i][j]){
  
  }
  </code></pre>
  
  <p>But yeah, tips or help are greatly appreciated. Actually I already turned it in, correct or not. But I want to know for future use</p>