This will try 5 times, if it returns false for some reason. You should check that the obtain lock actually succeeded before testing that it was locked. Those are two different errors: 1) tried to lock but couldn't, 2) it said it was locked but then when I checked it said it wasn't.