-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadTest1.java
More file actions
38 lines (30 loc) · 898 Bytes
/
ThreadTest1.java
File metadata and controls
38 lines (30 loc) · 898 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
38
package thread;
/**
* Created by Administrator on 2017/5/4 0004.
*/
public class ThreadTest1 {
public static void main(String[] args) {
Thread1 thread1 = new Thread1("张三");
Thread1 thread2 = new Thread1("李四");
// Thread1 thread2 = thread1; //start方法重复调用的话,会出现java.lang.IllegalThreadStateException异常
thread1.start();
thread2.start();
}
}
class Thread1 extends Thread{
private int count = 5;
private String name;
public Thread1(String name){
this.name=name;
}
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getName()+":"+name+"运行:count="+count--);
try {
sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}