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)- A8% (2)
- B4% (1)
- C83% (20)
- E4% (1)
Community Discussion
No community discussion yet for this question.