- Java.util.concurrent.locks.Lock
- void Lock (): Gets the lock that is blocked if the lock is owned by another thread
- void Unlock (): Release this lock
- Java.util.concurrent.locks.ReentrantLock
- Reentrantlock (): Build a reentrant lock
- Reentrantlock (Boolean Fair): Build a lock with fair policy (preference for the thread that schedules the longest waiting time)
- Java.util.concurrent.locks.Condition
- void await (): Places the thread in the waiting set of the condition
- void signal (): Randomly selects a thread from the waiting set of the condition, releasing its blocking state
- void Signal (): Unbind all blocked threads on the condition collection
- Synchronized keyword: The internal lock of object provides support for the keyword, which can be used to synchronize objects and methods, as well as the field of the class (synchronous blocking)
Strictly speaking, locks and conditions are not object-oriented. A successful solution is: monitor
- Volatile: Provides a lock-free mechanism for synchronizing access to instance domains
- Why synchronization: A computer on a multiprocessor can temporarily hold memory values in registers or local memory caches, resulting in different processors getting different values from the same memory; The compiler may change the order in which instructions are executed in order to maximize throughput, although the code semantics are unchanged, It is possible to cause an error when the program actually executes (another thread changes the value of the memory and violates the compiler's assumptions).
- There are 3 solutions for concurrent access to the domain: the domain is final and is accessed after the constructor is executed, the access to the domain is protected by a common lock, and the domain is volatile
- Java.util.concurrent.locks.ReentrantReadWriteLock
- Use for reader-writer issues
- Reentrantreadwritelock (): Gets the object
- Readlock () and Writelock (): Extracting Read and write locks
- Reader-read lock, write-write lock
-
- Java.util.concurrent.atomic. Atomicboolean (Implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomicintegerarray (Implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomicintegerfieldupdater<T>
- Java.util.concurrent.atomic. Atomiclongarray (Implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomiclongfieldupdater<T>
- Java.util.concurrent.atomic. atomicmarkablereference<V>
- Java.util.concurrent.atomic. atomicreference<V> (implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomicreferencearray<E> (implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomicreferencefieldupdater<T,V>
- Java.util.concurrent.atomic. atomicstampedreference<V>
- Java.lang. Number (Implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomicinteger (Implements Java.io.Serializable)
- Java.util.concurrent.atomic. Atomiclong (Implements Java.io.Serializable)
- Blocking queues:
- Java.util.concurrent.Deque
- Java.util.concurrent.Queue
Java.util.concurrent Package Brief Notes