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? 

package fence; import java.util.concurrent.atomic. *; public class CountSheep { private static Atomic

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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!