Skip to content

Commit bbc293a

Browse files
committed
ReenterLockCondition
1 parent c712308 commit bbc293a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package chapter3;
2+
3+
import java.util.concurrent.locks.Condition;
4+
import java.util.concurrent.locks.ReentrantLock;
5+
6+
/**
7+
* Created by 13 on 2017/5/5.
8+
*/
9+
public class ReenterLockCondition implements Runnable {
10+
public static ReentrantLock lock = new ReentrantLock();
11+
public static Condition condition = lock.newCondition();
12+
13+
@Override
14+
public void run() {
15+
16+
try {
17+
lock.lock();
18+
condition.await();
19+
System.out.println("Thread is going on");
20+
} catch (InterruptedException e) {
21+
e.printStackTrace();
22+
} finally {
23+
lock.unlock();
24+
}
25+
26+
}
27+
28+
public static void main(String args[]) throws InterruptedException {
29+
ReenterLockCondition reenterLockCondition = new ReenterLockCondition();
30+
Thread thread1 = new Thread(reenterLockCondition);
31+
thread1.start();
32+
System.out.println("˯Ãß2ÃëÖÓ");
33+
Thread.sleep(2000);
34+
lock.lock();
35+
condition.signal();
36+
lock.unlock();
37+
}
38+
}

0 commit comments

Comments
 (0)