-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise.java
More file actions
32 lines (27 loc) · 505 Bytes
/
Exercise.java
File metadata and controls
32 lines (27 loc) · 505 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
package com.tyss.multithreading;
public class Exercise extends Thread{
int max;
public Exercise(int max) {
super();
this.max = max;
}
@Override
public void run() {
try {
while(max>0) {
if(max%2==0) {
System.out.println(max);
Thread.sleep(1000);
}
max--;
}
}catch(Exception e) {
}
}
public static void main(String[] args) {
Exercise exercise = new Exercise(10);
exercise.start();
Exercise exercise2 = new Exercise(20);
exercise2.start();
}
}