-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartTest4Main.java
More file actions
36 lines (31 loc) · 906 Bytes
/
Copy pathStartTest4Main.java
File metadata and controls
36 lines (31 loc) · 906 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
package thread.start.test;
import util.MyLogger;
public class StartTest4Main {
public static void main(String[] args) {
PrintWork task1 = new PrintWork(1000,'A');
PrintWork task2 = new PrintWork(500,'B');
Thread threadA = new Thread(task1);
threadA.start();
Thread threadB = new Thread(task2);
threadB.start();
}
static class PrintWork implements Runnable{
int time;
char print;
public PrintWork(int time, char print){
this.time = time;
this.print = print;
}
@Override
public void run() {
while(true){
try {
Thread.sleep(time);
MyLogger.log(print);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}