Atomic integer, reference, array, updater - JUC - Concurrent Programming (Java)
1, Atomic integer
JUC also provided:
AtomicBooleanAtomicIntegerAtomicLong
Let's take AtomicInteger as an example to understand the common API s. All operations are atomic.
Self increasing:
incrementAndGet(): Auto increment and get, equivalent to + + igetAndIncrement(): get and auto increment, equivalent to i++ Self subtraction
dec ...
Posted by metalblend on Sun, 26 Sep 2021 20:22:29 -0700
5_ Thread safety for collections
1,ArrayList
1.1 thread unsafe demonstration
public class NotSafeDemo {
//Multiple threads modify the collection at the same time
public static void main(String[] args) {
List list = new ArrayList();
for (int i = 0; i < 100; i++) {
new Thread(() -> {
list.add(UUID.randomUUID().toStr ...
Posted by sstoveld on Mon, 20 Sep 2021 08:32:54 -0700