public interface Lock
可重入锁的接口
void lock();
锁定代码段的方法
void lockInterruptibly() throws InterruptedException;
当前线程没有被打断的情况下 才能获取锁
boolean tryLock();
尝试获取锁的方法
boolean tryLock(long time, TimeUnit unit) throws InterruptedException;
在一定时间内尝试获取锁的方法
void unlock();
解锁的方法
Condition newCondition();
创建新的Condition的方法
Lock接口介绍完毕
public interface Condition
Condition接口 就是将monitor的await notify一系列方法 分为多个对象来实现
void await() throws InterruptedException;
线程挂起的方法
void awaitUninterruptibly();
线程挂起并且不会被打断 直到接收到signal
long awaitNanos(long nanosTimeout) throws InterruptedException;
boolean await(long time, TimeUnit unit) throws InterruptedException;
都是在指定时间内一直挂起的方法 时间单位不同
boolean awaitUntil(Date deadline) throws InterruptedException;
直到某个时间点 一直挂起的方法
void signal();
唤醒一个被同样condition挂起的线程
void signalAll();
唤醒所有被同样condition挂起的线程
Condition接口讲解完毕