Question: Assuming the following class is concurrently accessed by numerous threads, which statement about the CountSheep class is correct? A. The class is thread-safe only if
Assuming the following class is concurrently accessed by numerous threads, which statement about the CountSheep class is correct?

A. The class is thread-safe only if increment1() is removed.
B. The class is thread-safe only if increment2() is removed.
C. The class is thread-safe only if increment3() is removed.
D. The class is already thread-safe.
E. The class does not compile.
F. The class compiles but may throw an exception at runtime.
package fence; import java.util.concurrent.atomic. *; public class CountSheep { private static Atomic Integer counter = new Atomic Integer (); private object lock = new Object (); public synchronized int increment1() { return counter.incrementAndGet (); } public static synchronized int increment2() { return counter.getAndIncrement (); } public int increment3() { synchronized (lock) { return counter.getAndIncrement (); } } }
Step by Step Solution
3.56 Rating (156 Votes )
There are 3 Steps involved in it
The class provided in the screenshot is a Java class named CountSheep which features a private static AtomicInteger member called counter and three di... View full answer
Get step-by-step solutions from verified subject matter experts
