nerdexam
Oracle

1Z0-819 · Question #41

1Z0-819 Question #41: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #41. The question stem and answer options stay visible for context.

Question

Given the two classes: public class Resource { public Worker owner; public synchronized boolean claim(Worker worker) { if (owner == null) { owner = worker; return true; } else return false; } public synchronized void release() { owner = null; } } public class Worker { public synchronized void work(Resource... resources) { for (int i = 0; i < 10; i++) { while (!resources[0].claim(this)) { } while (!resources[1].claim(this)) { } // do work with resources resources[1].release(); resources[0].release(); } } } And given this fragment: Worker w1 = new Worker(); Worker w2 = new Worker(); Resource r1 = new Resource(); Resource r2 = new Resource(); new Thread(() -> { w1.work(r1, r2); }).start(); new Thread(() -> { w2.work(r2, r1); }).start(); Which describes the fragment?

Options

  • AIt throws IllegalMonitorStateException.
  • BIt is subject to livelock.
  • CIt is subject to livelock.
  • DThe code does not compile.

Unlock 1Z0-819 to see the answer

You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-819 Practice