-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathInterruptTest.java
37 lines (37 loc) · 1.19 KB
/
InterruptTest.java
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
public class InterruptTest {
public static void main(String args[]) {
Thread current = Thread.currentThread();
System.out.println(current.isInterrupted());
current.interrupt();
System.out.println(current.isInterrupted());
System.out.println(current.isInterrupted());
System.out.println(Thread.interrupted());
System.out.println(current.isInterrupted());
current.interrupt();
synchronized (current) {
try {
current.wait(1);
System.out.println("no");
} catch (InterruptedException e) {
System.out.println(e.getClass());
}
}
synchronized (current) {
try {
current.wait(1);
System.out.println("yes");
} catch (InterruptedException e) {
System.out.println(e.getClass());
}
}
current.interrupt();
synchronized (current) {
try {
current.join();
System.out.println("yes");
} catch (InterruptedException e) {
System.out.println(e.getClass());
}
}
}
}