-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo11.java
More file actions
66 lines (54 loc) · 1.63 KB
/
Demo11.java
File metadata and controls
66 lines (54 loc) · 1.63 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
55
56
57
58
59
60
61
62
63
64
65
66
package Threads;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
//extends Thread
class Job implements Runnable {
private String fileName;
Job(String fileName) {
this.fileName = fileName;
}
@Override
public synchronized void run() {
System.out.println("Thread Start " + Thread.currentThread());
long startTime = System.currentTimeMillis();
try {
FileOutputStream fo = new FileOutputStream("C:\\MyData\\" + fileName);
BufferedOutputStream bo = new BufferedOutputStream(fo, 12000);
FileInputStream fi = new FileInputStream("C:\\MyData\\Test.dat");
BufferedInputStream bi = new BufferedInputStream(fi, 12000);
int singleChar = bi.read();
while (singleChar != -1) {
bo.write(singleChar);
singleChar = bi.read();
}
fo.close();
fi.close();
// bi.close();
// bo.close();
long endTime = System.currentTimeMillis();
System.out.println("File Done... " + Thread.currentThread());
System.out.println("Time Taken " + (endTime - startTime));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
* for(int i = 1; i<=5 ; i++){ System.out.println(" I is "+i
* +" Thread "+Thread.currentThread()); }
*/
}
}
public class Demo1 {
public static void main(String[] args) {
Job job1 = new Job("test2.dat");
// Job job2 = new Job("test3.dat");
Thread worker1 = new Thread(job1, "ram");
Thread worker2 = new Thread(job1, "shyam");
worker1.start();
worker2.start();
// System.out.println(Thread.currentThread());
}
}