Here's a class named Counter. The class has a single field count. An instance of the class is accessed by different threads concurrently. Each thread invokes the method inc to repeatedly increment the field.
After the completion of all threads, this field has an incorrect value.
Fix the code so that it can work correctly with multiple threads. Do not make the class public.
Example:
Let's assume we have one instance of Counter and two threads. Each thread invokes the method inc 5000000 times. If everything works correctly, after the completion of both threads, the value of count must be 10000000.