title: How did this synchronized code break?
body: <p>I have the following snippet of code.</p>
  
  <pre><code>synchronized (mObject) {
      if (mObject.variable != -1) {
          doThis();
          doThisAsWell();
          andThis();
          insertObjectInDb(); // This is crashing because mObject.variable is -1
      }
  }
  </code></pre>
  
  <p>To my knowledge, if I use synchronized on an object, and then run that block, the value of the variable can't be changed by any other thread, right? I don't understand how the value of the variable is -1, when I specifically check for that before entering the next block. And no, none of the functions in the block are changing the value. Have I completely misunderstood how these blocks work?</p>
  
  <p>If it matters at all, this is all in a doInBackground() method of an async task in an android app.</p>
  
  <p>Any ideas?</p>