✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
3.2 The following Java program attempts to create two threads that print numbers from 1 to 5. However, the output is sometimes incorrect or inconsistent.
Possible Output
a. Explain why does the output sometimes show numbers printed in a mixed order (e.g., Thread-B: 3 before Thread-A: 3)b. Write Java Code on how can we ensure that each thread prints numbers 1 to 5 sequentially (without mixing between threads)?c. Write Java Code on how can we make Thread-A complete its execution before Thread-B starts? (25 Marks)
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!