Win a copy of Terraform in Action this week in the Cloud forum!

hiti hitox

+ Follow
since Jan 23, 2003
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by hiti hitox

Yeah, this forum found, in which I can indicate as my success finally times.
I was lucky, as I at the end of February the examination to the SCJP1.2 existed and javaranch gratefully, for which many useful answers.
learn with the Jxam-tool, greens questions,java reference and many stupid 3 rows code.
18 years ago
A) isnt right, because of B)
Answer B) is right.
A call to setXY makes calls to the synchronized methods setX / setY.
But the method setXY isn't synchronized. So it can be called by multible threads.
When thread1 call setXY(8), method setX(8) called.
Here comes thread2 with call setXY(9).
Thread1 leaves setX(8) and call setY(8).
Now Thread2 can enter setX(9)
Thread1 call check() and ups! x==9, y==8!
C) Can't happen, cause setX/setY are private
D) completely beside it
Answer 2 is right. A good method to avoid deadlocks is to block the involved objects always in the same order, because the 2. thread can only enter code (an so block obj1), when the lock of obj2 AND obj1 is released.