-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJob.java
More file actions
47 lines (46 loc) · 1.81 KB
/
Copy pathJob.java
File metadata and controls
47 lines (46 loc) · 1.81 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
public class Job {
public int jobNumber;
public int totalTime; // How long job needs to run
public int timeLeft;
public int memoryNeeded; // How much memory this job needs
public String status; // "WAITING", "RUNNING", or "DONE"
public int blockNumber;
public int startTime; //when job started running
public int arrivalTime; // when job arrived to the system
public int waitTime; // time spent in waiting queue before start
//Constrsuctor for a new job
public Job(int jobNum, int time, int memory) {
this.jobNumber = jobNum;
this.totalTime = time;
this.timeLeft = time;
this.memoryNeeded = memory;
this.status = "WAITING";
this.blockNumber = -1;
this.startTime = -1;
this.arrivalTime = -1;
this.waitTime = 0;
}
public void tick() { //tick is a time unit
if (status.equals("RUNNING") && timeLeft > 0) { //checks if the job status is running and the time left is greater than 0
timeLeft--;
if (timeLeft == 0) {
status = "DONE"; //changes the job status to DONE
}
}
}
public void start(int currentTime, int block) { // method to start a job, takes in the current tick time and the assigned memory block
this.status = "RUNNING";
this.startTime = currentTime;
this.blockNumber = block;
if (arrivalTime >= 0) {
this.waitTime = currentTime - arrivalTime;
}
}
public void finish() {
this.status = "DONE";
this.blockNumber = -1;
}
public boolean isDone() { //checks is a job has finished
return status.equals("DONE");
}
}