-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathMain2.java
More file actions
35 lines (26 loc) · 765 Bytes
/
Main2.java
File metadata and controls
35 lines (26 loc) · 765 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
class MyThread extends Thread{
String name;
public MyThread(String name){
this.name = name;
}
@Override
public void run() {
for(int i = 0; i < 5; i++){
System.out.println("[" + Thread.currentThread().getId() + "]" + " " + name);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class Main2 {
public static void main(String[] args) throws InterruptedException {
MyThread myThread = new MyThread("线程");
System.out.println("线程");
myThread.start();
myThread.join(); //等待myThread执行结束
System.out.println("END");
}
}