-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintNums1to100.java
More file actions
46 lines (28 loc) · 783 Bytes
/
PrintNums1to100.java
File metadata and controls
46 lines (28 loc) · 783 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
39
40
41
42
43
44
45
46
package threadSynchronizationDemo;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class PrintNums1to100 {
public static void main(String[] args) {
for(int i=0;i<100;i++){
Print print = new Print(i);
Thread t=new Thread(print);
t.start();
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
class Print implements Runnable{
int count=0;
public Print(int count){
this.count=count;
}
@Override
public synchronized void run(){
System.out.println(count+" by "+Thread.currentThread().getName());
}
}