nerdexam
Oracle

1Z0-851 · Question #67

Given that Triangle implements Runnable, and: 31. void go() throws Exception { 32. Thread t = new Thread(new Triangle()); 33. t.start(); 34. for(int x = 1; x < 100000; x++) { 35. //insert code here…

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: 31. void go() throws Exception { 32. Thread t = new Thread(new Triangle()); 33. t.start(); 34. for(int x = 1; x < 100000; x++) { 35. //insert code here 36. if(x%100 == 0) System.out.print("g"); 37. } } 38. public void run() { 39. try { 40. for(int x = 1; x < 100000; x++) { 41. // insert the same code here 42. if(x%100 == 0) System.out.print("t"); 43. } 44. } catch (Exception e) { } 45. } 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

(52 responses)
  • A
    6% (3)
  • B
    12% (6)
  • C
    81% (42)
  • E
    2% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice