Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 171

Given these two classes:

And given this fragment:

Which describes the fragment?

    Correct Answer: C

    The given code is subject to livelock. In a livelock scenario, processes continuously change their state in response to other processes without making any progress. Here, there are two threads for the two Worker instances, w1 and w2, each trying to work with each other. Both workers call the isReady() method on the other and potentially enter an endless loop due to the continuous waiting and checking if the resource owner is different from themselves. Both threads may keep passing ownership of the resource back and forth without making any progress, resulting in a livelock situation. A deadlock, suggested by option B, would imply that both threads are stuck waiting for each other indefinitely, but here they keep changing their states. Hence, the correct answer is that the code is subject to livelock. The code does not throw an IllegalMonitorStateException, and it does compile, so the other options are incorrect.

Discussion
d7bb0b2Option: B

B is correct, if two worker are raeady at the same time w1 wait for w2 to work and w2 wait for w1.

RoxyFoxyOption: D

In the last fragment "resource. owner = w1; " does not compile.... owner is instance variable in Resource class. Where is declared the "resource" variable? That in work() method is local and does not compile...

RoxyFoxy

if "r.owner = w1" then will compile.

[Removed]Option: B

The answer is probably B but I'm kinda confused on where this wait(10) method comes from. It's not showing an static imports so let's assume this is valid

StavokOption: B

B is Correct