Question 2
Given the interface:
Which class implements IdGenerator in a thread-safe manner, so that no threats can get a duplicate id value during concurrent access?
Correct answer: B
Explanation:
An AtomicInteger is used in applications such as atomically incremented counters, and cannot be used as a replacement for an Integer. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes. The incrementAndGet() method atomically increments by one the current value. Reference: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html#incrementAndGet--
An AtomicInteger is used in applications such as atomically incremented counters, and cannot be used as a replacement for an Integer. However, this class does extend Number to allow uniform access by tools and utilities that deal with numerically-based classes.
The incrementAndGet() method atomically increments by one the current value.
Reference: http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html#incrementAndGet--