Java.util.concurrent.locks.ReentrantLock

Source: Internet
Author: User

---restore content starts---

Reentrantlockextends objectimplements Lock, Serializable

One reentrant Mutex ...


Multithreaded access programs that use fair locks may show lower throughput performance than those using the default settings (that is, slow, often much slower), but the gap between time and "get lock" is smaller and ensures no starvation.
However, it is important to note that the fairness of the lock does not guarantee the fairness of the thread scheduling. That is, a thread that uses a fair lock may successfully acquire a lock multiple times when another active state thread is not running and is not currently getting a lock. It is also important to note that the Trylock () is not timed.
The method does not follow the fairness setting, even if there are other threads waiting, as long as the lock is available trylock () will succeed.
It is recommended that you always call the lock () method followed by a try{} code block in the actual operation, with the following typical structure:
  
Class X {   private final reentrantlock lock = new Reentrantlock ();   // ...   public void M () {     lock.lock ();  Block until condition holds     try {       //... method body     } finally {       lock.unlock ()   }}}

In addition to implementing the lock interface, the class defines the islocked and Getlockqueuelength methods, as well as some related methods of protected access adornments, which may be useful for monitoring and monitoring locks.

Java.util.concurrent.locks.ReentrantLock

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.