-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathReenterLockCondition.java
More file actions
31 lines (27 loc) · 875 Bytes
/
Copy pathReenterLockCondition.java
File metadata and controls
31 lines (27 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ch3.s1;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
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 r1 = new ReenterLockCondition();
Thread t1= new Thread(r1);
t1.start();
Thread.sleep(2000);
lock.lock();
condition.signal();
lock.unlock();
}
}