We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a24aa07 commit 532229dCopy full SHA for 532229d
src/main/java/chapter_13/code_05/InterruptibleLocking.java
@@ -0,0 +1,24 @@
1
+package chapter_13.code_05;
2
+
3
+import java.util.concurrent.locks.Lock;
4
+import java.util.concurrent.locks.ReentrantLock;
5
6
+/**
7
+ * 程序清单 13-5 可中断的锁获取操作
8
+ */
9
+public class InterruptibleLocking {
10
+ private Lock lock = new ReentrantLock();
11
12
+ public boolean sendOnSharedLine(String message) throws InterruptedException {
13
+ lock.lockInterruptibly();
14
+ try {
15
+ return cancellableSendOnSharedLine(message);
16
+ } finally {
17
+ lock.unlock();
18
+ }
19
20
21
+ private boolean cancellableSendOnSharedLine(String message) throws InterruptedException {
22
+ return true;
23
24
+}
0 commit comments