-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterruptTest.java
More file actions
42 lines (39 loc) · 999 Bytes
/
Copy pathInterruptTest.java
File metadata and controls
42 lines (39 loc) · 999 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
32
33
34
35
36
37
38
39
40
41
42
package lockTest;
import java.util.concurrent.locks.*;
public class InterruptTest {
public static void main(String[] args) throws Exception {
MyThread05 mt = new MyThread05();
mt.test3();
}
}
class MyThread05 extends Thread {
public void test3() throws Exception {
final Lock lock = new ReentrantLock();
lock.lock();
Thread.sleep(1000);
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
// lock.lock();
try {
lock.lockInterruptibly();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// try {
// lock.lockInterruptibly();
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
System.out.println(Thread.currentThread().getName() + " interrupted.");
}
});
t1.start();
Thread.sleep(1000);
t1.interrupt();
// t1.interrupt();
Thread.sleep(1000000);
}
}