I have the following snippet of code.
synchronized (mObject) {
    if (mObject.variable != -1) {
        doThis();
        doThisAsWell();
        andThis();
        insertObjectInDb(); // This is crashing because mObject.variable is -1
    }
}
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?
If it matters at all, this is all in a doInBackground() method of an async task in an android app.
Any ideas?
 
     
     
     
    