-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadTest3.java
More file actions
45 lines (42 loc) · 1.29 KB
/
ThreadTest3.java
File metadata and controls
45 lines (42 loc) · 1.29 KB
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
43
44
45
package thread;
/**
* Created by Administrator on 2017/5/5 0005.
*/
public class ThreadTest3 extends Thread{
private String name;
public ThreadTest3(String name){
this.name = name;
}
public void run(){
System.out.println(Thread.currentThread().getName()+"现成开始---");
for (int i = 0; i < 5; i++) {
System.out.println("子线程"+name + "运行 : " + i);
try {
sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName() + " 线程运行结束!");
}
}
class Test2{
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName()+"主线程运行开始!");
ThreadTest3 thread1 = new ThreadTest3("A");
ThreadTest3 thread2 = new ThreadTest3("A");
thread1.start();
thread2.start();
try {
thread1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+ "主线程运行结束!");
}
}