美文网首页
lock获取锁的四种方式

lock获取锁的四种方式

作者: henry随笔 | 来源:发表于2018-04-17 10:43 被阅读0次

lock.lock();获取锁,如被锁定则等待

lock.tryLock();如未被锁定才获取锁

lock.tryLock(long timeout, TimeUnit unit);获取锁,如已被锁定,则最多等待timeout时间后返回获取锁状态

lock.lockInterruptibly();如当前线程未被interrup才获取锁.

相关文章

网友评论

      本文标题:lock获取锁的四种方式

      本文链接:https://www.haomeiwen.com/subject/ksqukftx.html