-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.java
More file actions
52 lines (35 loc) · 1.13 KB
/
Copy pathdata.java
File metadata and controls
52 lines (35 loc) · 1.13 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
package threads;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
public class data implements Callable {
CountDownLatch latch;
public data(CountDownLatch latch){
this.latch=latch;
}
@Override
public LinkedList<Integer> call() throws Exception {
// TODO Auto-generated method stub
LinkedList<Integer> list=new LinkedList<Integer>();
try {
File myObj = new File("/Users/subrat/Downloads/lowlevelDesign/src/threads/numbers.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
list.add(Integer.valueOf(data));
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
latch.countDown();
return list;
}
}