Search⌘ K
AI Features

Quiz 2

Learn to identify thread-safe classes and detect race conditions in Java concurrency. Understand scenarios like check-then-act and read-modify-write that cause race conditions, using practical code examples to build foundational multithreading knowledge.

We'll cover the following...

Question # 1

What is a thread safe class?

A class is thread safe if it behaves correctly when accessed from multiple threads, irrespective of the scheduling or the interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code.

Question # 2

Is the following class thread-safe?

public class Sum {

    int sum(int... vals) {

        int total = 0;
        for (int i = 0; i < vals.length; i++) {
            total += vals[i];
        }
        return total;
    }
}
Technical Quiz
1.
A.

Yes

B.

No


1 / 1

Show Explanation

The class Sum is ...