Так как AtomicInteger
может быть как минимум на порядок медленнее, чем a int
, защищенным synchronized
, зачем мне когда-либо хотеть использовать AtomicInteger?
Например, если все, что я хочу, - это увеличить значение int
в потокобезопасном режиме, почему бы всегда использовать:
synchronized(threadsafeint) {
threadsafeint++;
}
вместо использования гораздо медленнее AtomicInteger.incrementAndGet()?