nerdexam
Oracle

1Z0-851 · Question #244

Given that Triangle implements Runnable, and: void go() throws Exception { Thread t = new Thread(new Triangle()); t.start(); for(int x = 1; x < 100000; x++) { //insert code here if(x%100 == 0)…

The correct answer is C. Thread.yield(); D. Thread.sleep(1). See the full explanation below for the reasoning.

Question

Given that Triangle implements Runnable, and: void go() throws Exception { Thread t = new Thread(new Triangle()); t.start(); for(int x = 1; x < 100000; x++) { //insert code here if(x%100 == 0) System.out.print("g"); } } public void run() { try { for(int x = 1; x < 100000; x++) { // insert the same code here if(x%100 == 0) System.out.print("t"); } } catch (Exception e) { } } Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.)

Options

  • AThread.wait();
  • BThread.join();
  • CThread.yield();
  • DThread.sleep(1);
  • EThread.notify();

How the community answered

(24 responses)
  • A
    8% (2)
  • B
    4% (1)
  • C
    83% (20)
  • E
    4% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice