-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05Race.java
More file actions
36 lines (30 loc) · 972 Bytes
/
Copy path05Race.java
File metadata and controls
36 lines (30 loc) · 972 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
import java.util.ArrayList;
import java.util.List;
public class Main {
private static int downloadedBytes = 0;
public static void main(String[] args) throws InterruptedException {
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Thread thread = new Thread(new FileDownloader());
thread.start();
threads.add(thread);
}
for (Thread thread : threads) {
thread.join();
}
System.out.println("Total Downloaded bytes: " + downloadedBytes);
}
public static class FileDownloader implements Runnable {
@Override
public void run() {
for (int j = 0; j < 10; j++) {
downloadedBytes++;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}