| preferred AP College board partner for AP classes
AP Computer Science A/Unit 1: Primitive Types
Start Practice TestPractice Test
About Exam
hard Solved by 2 students
Unsynchronized Multi-threaded Printing
< Prev
Next >

Consider the following code. What is the most likely outcome related to the output produced by this multi-threaded program?

public class InterleavedPrint {
    public static void main(String[] args) {
        Runnable printTask = () -> {
            for(int i = 0; i < 5; i++) {
                System.out.print(Thread.currentThread().getName() + " ");
            }
        };
        new Thread(printTask, "Thread1").start();
        new Thread(printTask, "Thread2").start();
    }
}
A

The output may be interleaved due to unsynchronized printing from multiple threads.

B

The code will result in a deadlock because both threads contend for the print statement.

C

A race condition will cause the program to crash unexpectedly.

D

The threads will execute in a strictly sequential order based on the system scheduler.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1ravi.palepu11 0m 00s 100
#2701704601 0m 00s -10
#3ansonjia137102 0m 00s -20
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy