Quiz 2
Questions on thread-safety and race conditions
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;
}
}
Q
A)
Yes
B)
No
...