My problem is: I have class: I need to add new characters to StringBuilder concurrently and atomically. But problem is, only last 128 characters should be in this object. I can’t use StringBuffer, because operation should be non-blocking. So,there are two operations: First: check if StringBuilder already has 128 chars. Second: if it has not -> add new char, if
Tag: atomicreference
What is a usecase for Java AtomicReference#getAndSet?
What is a usecase for Java AtomicReference#getAndSet? In other words, is it correct assumption, that if the only method from AtomicReference that I use in my code is AtomicReference#getAndSet, then I do not need AtomicReference at all, just a volatile variable would be enough? For example, if I have the next code: , isn’t it always doing exactly the same