The whole purpose of using AtomicInteger is to increment atomically i.e. in a single operation. In this option, you are incrementing ai in two separate calls, which is not thread safe. Between the time when ai.get() returns a value and ai.set() is called, some other thread may call ai.set with the same value. This will make the count incorrect.
HTH,
Paul.