-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadTest2.java
More file actions
38 lines (33 loc) · 995 Bytes
/
ThreadTest2.java
File metadata and controls
38 lines (33 loc) · 995 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;
import static java.lang.Thread.sleep;
/**
* Created by Administrator on 2017/5/4 0004.
*/
public class ThreadTest2 implements Runnable{
private int count = 15;
private String name;
public ThreadTest2(String name){
this.name= name;
}
@Override
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();
}
}
}
}
class Test{
public static void main(String[] args) {
// new Thread(new ThreadTest2("张三")).start();
// new Thread(new ThreadTest2("李四")).start();
ThreadTest2 threadTest2 = new ThreadTest2("张三");
new Thread(threadTest2,"A").start();
new Thread(threadTest2,"B").start();
new Thread(threadTest2,"C").start();
}
}