java- lock Classification

Lock Category

  • Spin locks: Thread state and context switching consumes system resources, access to shared resources when short time, frequent context switching is not worth it. jvm achieve the thread when we do not get the lock, it is not suspended in favor of the implementation of air circulation, after several cycles, if not been able to get the lock, it is suspended.
  • Blocking locks: blocking locks changed operational state of the thread, so that thread into the blocked state to wait, when obtaining a corresponding signal (or wake-up time), before they can enter the ready state of the thread, all the thread into the ready state, through competition, went into operation.
  • Reentrant lock: Support thread goes back to the lock, just like we have a room key, you can enter the room several times similar.
  • Write lock: two locks, read locks with a write lock, exclusive write, read and write mutually exclusive, shared read.
  • Mutex: the toilet, put the door after door shut, do not let other people come in.
  • Pessimistic locks: always assume the worst case, get a time when data modification think others will, so every time she took the data will be locked, so people want to take this data will be blocked until the lock to get it .
  • Optimistic locking: every time that others pick up data are not modified, so it will not be locked, but when the update will determine what others during this time did not go to update the data, you can use the mechanisms of the version number.
  • Fair locks: Everyone line up honestly to all of us in terms of very fair.
  • Unfair lock: some people lined up, but newcomers may jump the queue.
  • Biased locking: the use of a biased locking mechanism until it releases the lock of competition there, so when another thread tries to lock biased competition, held biased locking thread will release the lock.
  • Exclusive lock: In an exclusive lock mode, you can only have one thread can hold the lock.
  • Shared lock: allows multiple threads simultaneously acquire a lock, concurrent access to shared resources.

Guess you like

Origin www.cnblogs.com/woxbwo/p/11441276.html