3.1.2 condition 条件

package 第三章.重入锁;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
* Created by zzq on 2018/1/23.
*/
public class ReenterLockCondition implements Runnable {
public static ReentrantLock lock = new ReentrantLock();
public static Condition condition = lock.newCondition();

public void run() {

try {
lock.lock();
condition.await();
System.out.println("Thread is going on");
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}

}

public static void main(String args[]) throws InterruptedException {
ReenterLockCondition reenterLockCondition = new ReenterLockCondition();
Thread thread1 = new Thread(reenterLockCondition);
thread1.start();
Thread.sleep(2000);
lock.lock();
condition.signal();
System.out.println("hahahah");
lock.unlock();
System.out.println("hiiiiiiiii");
}
}
posted @ 2018-02-07 10:42  anxbb  阅读(193)  评论(0编辑  收藏  举报