Originally posted by Andrew Cheng:
Under which conditions will check() return true when called from adifferent class?
A. check() can never return true
B. check()can return true when setXY is called by multiple threads
C. check()can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SynchTest is changed to allow x and y to be set separately.
The answer is C.
I am not clear about the question.Please explain in detail.Thank in advance!
:roll:
Hi Andrew
Well the condition in the check method is X != Y. So if you use the answer B that means you have synchronized the threads and that both of the values are going to be equal. X!=Y is going to return false, while if you call setX & setY seperately you are not synchronizing the behavior so any
thread can call any method with any value and the check X!=Y is going to return true, SO the answer C is right setX & setY called seperately will return true.
Hope this helps
