-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
60 lines (50 loc) · 1.31 KB
/
ReadFile.java
File metadata and controls
60 lines (50 loc) · 1.31 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
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
public class ReadFile implements Runnable{
BufferedReader in;
OperatingSys OS;
public ReadFile(String filein, OperatingSys OS){
try{
in = new BufferedReader(new FileReader(filein));
}catch (FileNotFoundException e){
e.printStackTrace();
}
this.OS = OS;
}
//This makes it so that the read process will execute on a thread
@Override
public void run(){
String line = "";
ArrayList<String> tokenized;
try{
while((line = in.readLine()) != null){
line = line.trim();
tokenized = new ArrayList<String>(Arrays.asList(line.split("\\s")));
switch(tokenized.get(0)){
case "proc" :
ProcessControlBlock block = new ProcessControlBlock(OS.total, tokenized);
OS.total += 1;
OS.CPUq.add(block);
break;
case "sleep" :
Thread.sleep(Integer.parseInt(tokenized.get(1)));
break;
case "stop" :
return;
default :
System.out.println("Reading error has occurred");
}
}
}catch(IOException e){
e.printStackTrace();
}catch(NumberFormatException e){
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}