Java.util.concurrent Package Brief Notes

Source: Internet
Author: User

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.