This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Nuwan Arambage wrote:Question is this, Why wouldn't I get the expected output by executing previously mentioned code.
Let's reverse the question. Why do you expect to get the expected output by executing the first set of code? Why do you expect the whole loop to be atomic, when you grab (and release) the lock per each iteration of the loop?