File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments