-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiThread.java
More file actions
58 lines (49 loc) · 1.3 KB
/
MultiThread.java
File metadata and controls
58 lines (49 loc) · 1.3 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
46
47
48
49
50
51
52
53
54
55
56
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by lock on 2016/11/11.
*/
public class MultiThread extends Thread {
/**
* 线程名字,可以不实现
* @param tName
*/
public MultiThread(String tName){
super(tName);
}
/**
* 继承 Thread 类 ,并且实现run方法
*/
public void run(){
for (int row = 1; row < 10; row++){
for (int i = 0; i < row; i++) {
print("*");
}
echo("");
}
try {
sleep(2000);
}catch (Exception e){
echo(e.getMessage());
}
Date date = new Date();
DateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss:SSS");
String time = format.format(date);
echo("I am sleep , time is: "+time+" thread name is:"+this.getName());
}
public static void main(String args[]){
MultiThread t1 = new MultiThread("a");
MultiThread t2 = new MultiThread("b");
MultiThread t3 = new MultiThread("c");
t1.start();
t2.start();
t3.start();
}
public static void echo(String msg){
System.out.println(msg);
}
public static void print(String msg){
System.out.print(msg);
}
}