Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (31 loc) · 961 Bytes

File metadata and controls

34 lines (31 loc) · 961 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* @author xjn
* @since 2020-02-29
*/
public class Demo {
private static Object obj = new Object();
public static void main(String[] args) {
Runnable run = () -> {
synchronized (obj) {
String name = Thread.currentThread().getName();
System.out.println(name + "进入同步代码块");
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
};
Thread t1 = new Thread(run);
t1.setName("t1");
t1.start();
Thread t2 = new Thread(run);
t2.setName("t2");
t2.start();
System.out.println("停止线程前");
t2.interrupt();
System.out.println("停止线程后");
System.out.println(t2.getName() + " " + t2.getState());
System.out.println(t1.getName() + " " + t1.getState());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.