Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 165

Given:

What change should you make to guarantee a single order of execution (printed values 1 -100 in order)?

    Correct Answer: A

    To ensure a single order of execution where the printed values are in order from 1 to 100, the run() method should be synchronized. By synchronizing the run() method, you prevent multiple threads from accessing it simultaneously and ensure that the increment and print operations occur atomically for each value. This change will guarantee an orderly execution of the values.

Discussion
Abdullah_Rahahleah

Myclass mc = new Thread(mc) has a compilation error

mevltOption: A

Answer A

pul26Option: A

Answer is A

steefaandOption: A

A is correct.

WilsonKKerllOption: A

Answer is A. Change-> MyClass mc = new MyClass(); Thread a = new Thread(mc); a.start(); Thread b = new Thread(mc); b.start();

Svetleto13Option: A

I am agreed with you.Answer is A,tested with MyClass mc = new MyClass();

Svetleto13

I changed it to MyClass mc = new MyClass(); and compile or even if we try with class MyClass extends Thread or public synchronized run() is still compile.So compiltion error is answer.