public class ThreadDemo { static Thread laurel, hardy; public static void main(S
ID: 3660303 • Letter: P
Question
public class ThreadDemo { static Thread laurel, hardy; public static void main(String[] args) { laurel = new Thread() { public void run() { System.out.println("A"); try { hardy.sleep(1000); } catch (Exception e) { System.out.println("B"); } System.out.println("C"); } }; hardy = new Thread() { public void run() { System.out.println("D"); try { laurel.wait(); } catch (Exception e) { System.out.println("E"); } System.out.println("F"); } }; laurel.start(); hardy.start(); } } [Answer to next question by using above code: Which letters will eventually appear somewhere in the output? Why? (Choose all that apply.) 1. A 2. B 3. C 4. D 5. E 6. F 7. The answer cannot be reliably determined. 8. The sequence of the output cannot be reliably determined. (Please explain how you get your answer)Explanation / Answer
8. The sequence of the output cannot be reliably determined ( A, C , D, E, F are the characters displayed in the output)
Explanation: Multithrading is the concept of executing more than one thread simultaneously to keep the CPU busy (effective utilization of CPU). So whenever we try to execute multiple threads there is no guarantee of the order of execution of the threads. It may choose any thread that is ready for execution.So the sequence of the output cannot be reliably determined.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.