Sike high concurrency and network programming study notes summary and (c)

The third phase

1, type atomic explain in detail
AtomicInteger (compareAndSet typical cas comparison algorithm)
releases the lock when taking into account the multi-threaded, only the current thread can close the current thread

1, visibility
2, compliant
3, atomicity

1, volatile modified variables, both to ensure the former's
2, CAS algorithm, which is the CPU instruction-level synchronization, the equivalent of optimistic locking, which can detect changes in other threads to shared data case

atomicInteger++
incrementAndGet()

for(;;){
    int current = get();
    int next = current +1;
    if(compareAndSet(current,next))
        return next;
}

The fastest failure policy

CAS lightweight lock, caused a serious problem, ABA problem

T1     T2
A    A->B->A

Linked lists, stacks, LIFO


2, and contracting tools
CountDwonLatch


3, Executors frame details

4. Concurrent collections

Guess you like

Origin blog.csdn.net/weixin_39650971/article/details/94637750
Recommended