其他分享
首页 > 其他分享> > lock相关代码

lock相关代码

作者:互联网

 

 

package com.study.lock;

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

public class Demo3_Condition {
private static Lock lock = new ReentrantLock();
private static Condition condition = lock.newCondition();

public static void main(String[] args) throws InterruptedException {
Thread th = new Thread(new Runnable() {
@Override
public void run() {
lock.lock();
System.out.println("condition.await()");
try {
condition.await();
System.out.println("here i am...");
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
lock.unlock();
}
}
});

th.start();


Thread.sleep(2000L);
lock.lock();

condition.signalAll();

lock.unlock();

}

}

标签:java,lock,代码,locks,static,new,相关,condition
来源: https://www.cnblogs.com/wscp/p/15615765.html