We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5edff68 commit 442617bCopy full SHA for 442617b
1 file changed
03concurrency/0301/src/main/java/java0/conc0302/threadpool/ReentrantLockTest.java
@@ -0,0 +1,34 @@
1
+package java0.conc0302.threadpool;
2
+
3
+import java.util.concurrent.locks.Lock;
4
+import java.util.concurrent.locks.ReentrantLock;
5
6
+/**
7
+ * @Desc
8
+ * @Author wfy
9
+ * @Date 2021/2/3 18:05
10
+ */
11
+public class ReentrantLockTest {
12
+ static Lock lock = new ReentrantLock(true);
13
+ static int count = 0;
14
15
+ public static void main(String[] args) {
16
+ for (int i = 0; i < 10; i++) {
17
+ new Thread(ReentrantLockTest::incr).start();
18
+ }
19
20
21
22
+ public static void incr() {
23
+ lock.lock();
24
+ try {
25
+ for (int i = 0; i < 10000; i++) {
26
+ count++;
27
+ System.out.println(count);
28
29
+ } finally {
30
+ lock.unlock();
31
32
33
34
+}
0 commit comments