This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
why is the answer not guarenteed to be 2000? arent setNumber and getNumber synchronized...is this becasue both the threads have entered the run method and started the loop...and once the first thread finishes with setNumber and getNumber the other one can start it enter too...........?
scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
The problem is that although the setNumber and getNumber methods are synchronized,
the action of getting and setting the number is not atomic. Therfore it is possible
for a thead call getNumber and before it has time to call setnumber , another thread
may nip in and call getNumber, thus both threads will call setnumber using the same
number. This can be avoided by combining setNumber and getNumber in one