Difference between synchronized and reentrantlock? Pros and Cons [closed]
来源:互联网 发布:空军飞行员知乎 编辑:程序博客网 时间:2024/05/21 19:23
A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities.
From: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReentrantLock.html
Extended capabilities include:
- The ability to have more than one condition variable per monitor. Monitors that use the synchronized keyword can only have one. This means reentrant locks support more than one wait()/notify() queue.
- The ability to make the lock "fair". "[fair] locks favor granting access to the longest-waiting thread. Otherwise this lock does not guarantee any particular access order." Synchronized blocks are unfair.
- The ability to check if the lock is being held.
- The ability to get the list of threads waiting on the lock.
The disadvantages of reentrant locks are:
- Need to add import statement.
- Need to wrap lock acquisitions in a try/finally block. This makes it more ugly than the synchronized keyword.
- The synchronized keyword can be put in method definitions which avoids the need for a block which reduces nesting.
- Difference between synchronized and reentrantlock? Pros and Cons [closed]
- Pros and cons of SVM
- C++ Exceptions: Pros and Cons
- Pros and Cons of Angularjs
- difference between Lock and synchronized
- The pros and cons of job hopping
- Pros and Cons of AngularJS (转)
- The Pros and Cons of Pair Programming
- Pros and Cons of X command vs. SYSTASK command
- pros & cons of Meson,CMake, Autotools and Tup
- Difference between HashMap and HashTable? Can we make hashmap synchronized?
- Java - Difference between ConcurrentHashMap, Hashtable and Synchronized Map
- The difference between (()) and ().
- difference between "<" and "<<"
- Difference Between typedef and #define
- Difference between PCDATA and CDATA
- Difference between CComPtr and CComQIPtr
- Difference between RVCT and GCCE
- 2012.5.28 C# ??
- [转]软件开发技术高手转向项目管理者要突破的误区
- c++ stack
- CXF 基础教程-------入门示例
- 网络编程——非阻塞模式(ioctlsocket)
- Difference between synchronized and reentrantlock? Pros and Cons [closed]
- Android创建新的视图(二)之创建复合控件
- 非常道
- SVN branch merge
- C# 将新打开的窗体置为最顶层
- c++学习看看
- 从程序员到项目经理(14):项目经理必须懂一点“章法”
- ExtJS学习笔记
- ASP中实现分页显示的七种武器