一、Lock锁接口
定义Java中Java.Util.concurrent 中锁 Lock 的基本接口方法
二、Lock 接口方法
Lock 接口有以下几个方法
public interface Lock { void lock(); void lockInterruptibly() throws InterruptedException; boolean tryLock(); boolean tryLock(long time, TimeUnit unit) throws InterruptedException; void unlock(); Condition newCondition(); }
lock() 是一直等到获取锁
void lock();
tryLock() 是尝试获取锁
boolean tryLock();
tryLock(Long time, TimeUnit time) 设置尝试在某个时间内获取锁,过了这个时间就不尝试获取了
boolean tryLock(long time, TimeUnit unit) throws InterruptedException;
lockInterruptibly 中止锁
void lockInterruptibly() throws InterruptedException;
unlock( ) 解锁
unlock();
newCondition 稍后解释
Condition newCondition();
三、lock 使用
Lock的使用,通过实现Lock接口的 ReentranLock 类来实现;
原文:https://www.cnblogs.com/Jomini/p/13443683.html