Answer by Tom Anderson for Synchronization while using AtomicInteger
If you desperately wanted to use AtomicInteger, you could write:public class Account { private final AtomicInteger balance = new AtomicInteger(0); public void deposit(int amount) {...
View ArticleAnswer by afsantos for Synchronization while using AtomicInteger
Yes, you are correct. AtomicInteger would not grant any benefit if all access to the object is synchronized (only one thread, at most, would be accessing its contents at any given moment).As others...
View ArticleAnswer by Ravi K Thapliyal for Synchronization while using AtomicInteger
All that an atomic data type is promising you is to give a lock-free but thread-safe access to its value. So, one of the valid reasons you would use an AtomicInteger over synchronized is when you need...
View ArticleAnswer by i Code 4 Food for Synchronization while using AtomicInteger
Yes for both, it is a good idea to make it synchronized, and Atomic is not needed.If you rely simply on Atomic instead of synchronization, you can have issues such as in this method: if...
View ArticleAnswer by omnomnom for Synchronization while using AtomicInteger
Having your amount declared as AtomicInteger does not prevent the thread from being preempted in the middle of method execution (if it's not synchronized). So for example if your method transfer_funds...
View ArticleSynchronization while using AtomicInteger
Let's assume that I want to implement a very simple Bank Account class , and we want to take care about concurrency and multi-threading issues,Is it a good idea to make the following methods...
View Article
More Pages to Explore .....