We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3171394 commit 01df6a9Copy full SHA for 01df6a9
1 file changed
src/chapter03/ReentrantLockExample.java
@@ -0,0 +1,32 @@
1
+package chapter03;
2
+
3
+import java.util.concurrent.locks.ReentrantLock;
4
5
+class ReentrantLockExample {
6
7
+ int a = 0;
8
+ ReentrantLock lock = new ReentrantLock();
9
10
+ public void writer() {
11
12
+ lock.lock(); // »ñÈ¡Ëø
13
14
+ try {
15
+ a++;
16
+ } finally {
17
+ lock.unlock(); // ÊÍ·ÅËø
18
+ }
19
20
21
+ public void reader() {
22
23
24
25
26
+ int i = a;
27
+ // ¡¡
28
29
30
31
32
+}
0 commit comments