Dear all,
Question n�19 from Dan's (third part) devoted to threads:
Answer for possible outputs:
Prints: [T1,A][T2,B].
c. Prints: [T1,B][T2,B].
d. Prints: [T2,B][T1,A].
e. Prints: [T2,A][T1,A].
Since method m1 is not synchronized
As far as I understand, here the modifier
static for object b in class A is very important: it means that the same object B is shared between the two threads a and b.
But if we delete this keyword in the code, now each
thread has its own object b, and there is no more reason that we obtain a different result than
[T1,A][T2,B]
I've tested it, and on my computer, that's indeed the case.
But may we generalize?
Thanks in advance for your answer,
Cyril.
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287