码迷,mamicode.com
首页 > 其他好文 > 详细

when to use reentrant lock

时间:2015-08-18 21:17:28      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

The answer is pretty simple -- use it when you actually need something it provides that synchronized doesn‘t,

like timed lock waits, interruptible lock waits, non-block-structured locks, multiple condition variables, or lock polling.

ReentrantLock also has scalability benefits, and you should use it if you actually have a situation that exhibits high contention,

but remember that the vast majority of synchronized blocks hardly ever exhibit any contention, let alone high contention.

I would advise developing with synchronization until synchronization has proven to be inadequate,

rather than simply assuming "the performance will be better" if you use ReentrantLock. Remember, these are advanced tools for advanced users.

(And truly advanced users tend to prefer the simplest tools they can find until they‘re convinced the simple tools are inadequate.)

As always, make it right first, and then worry about whether or not you have to make it faster.

when to use reentrant lock

标签:

原文地址:http://www.cnblogs.com/glf2046/p/4740568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!