Quiz 5
Exercise on how to make classes thread-safe
We'll cover the following...
We'll cover the following...
Question # 1
Is the following class thread-safe?
public class Sum {
int count = 0;
int sum(int... vals) {
count++;
int total = 0;
for (int i = 0; i < vals.length; i++) {
total += vals[i];
}
return total;
}
void printInvocations() {
System.out.println(count);
}
}
Technical Quiz
1.
A.
Yes
B.
No
1 / 1
Show Explanation
Question # 2
What are the different ways in which we can make the ...