Sergey Izg wrote:
I expect to see output 500, it's not the case.
Could you please help understand what am i doing wrong here?
Henry Wong wrote:
Sergey Izg wrote:
I expect to see output 500, it's not the case.
Could you please help understand what am i doing wrong here?
First, welcome to the ranch.
You have two issues. One. Your getInstance() method is not thread safe. It is possible for different threads to have different data instances. Two. Your updateUnit() method is not thread safe. The operation is not atomic, and it is this issue that is causing your result to be less than expected.
Henry
"Il y a peu de choses qui me soient impossibles..."
Sergey Izg wrote:Or, synchronized is not about read?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here