-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadFileTask.java
More file actions
54 lines (45 loc) · 1.49 KB
/
DownloadFileTask.java
File metadata and controls
54 lines (45 loc) · 1.49 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
package java;
public class DownloadFileTask implements Runnable{
private DownloadStatus status;
public DownloadFileTask(DownloadStatus status) {
this.status = status;
}
public void run(){
for (int i = 0; i < 10_000; i++) {
status.incrementTotalBytes();
}
}
public DownloadStatus getStatus() {
return status;
}
// wait() and notify()
// public void run() {
// for (int i = 0; i < 1_000_000; i++) {
// status.incrementTotalBytes();
// }
// status.done();
// synchronized(status){
// status.notify();
// }
// }
// confinement race condition
// public DownloadFileTask(){
// this.status = new DownloadStatus();
// }
// for race condition.
// public DownloadFileTask(DownloadStatus status) {
// this.status = status;
// }
//@SuppressWarnings("static-access")
/* ----------------------------------------------------------------------
System.out.println("Downloading a File : " + Thread.currentThread().getName());
for (int i = 0; i < Integer.MAX_VALUE; i++) {
if(Thread.currentThread().interrupted()) return; //checks for interruption, if not found continues forever.
System.out.println("Bytes Downloaded : " + i);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} */
}