-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterruptDemo.java
More file actions
37 lines (33 loc) · 993 Bytes
/
Copy pathInterruptDemo.java
File metadata and controls
37 lines (33 loc) · 993 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
package thread.demo2;
/**
* @Author: wei1
* @Date: Create in 2019/1/1 10:41
* @Description:
*/
public class InterruptDemo {
public static void main(String[] args) throws InterruptedException {
Object lock = new Object();
WriterReader writerReader = new WriterReader();
Thread writer = new Thread(new Runnable() {
@Override
public void run() {
writerReader.write();
}
});
writer.start();
Thread reader = new Thread(new Runnable() {
@Override
public void run() {
writerReader.read();
}
});
reader.start();
Thread.sleep(10);
// writer.interrupt();
reader.interrupt();
System.out.println("reader.isInterrupted():" + reader.isInterrupted());
Thread.sleep(10000);
System.out.println("reader.isInterrupted():" + reader.isInterrupted());
writer.interrupt();
}
}