Skip to content

Commit

Permalink
printgannt() and thread reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Langensiepen committed May 19, 2013
1 parent 6adbc6c commit a94db77
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
17 changes: 13 additions & 4 deletions Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ public class Job extends Thread {
SystemSimulator s;
String name;
private boolean running;
private int actualRuntime;

Job(String description, SystemSimulator s, String name) {
this.description = description;
this.s = s;
this.name = name;
}

public int getActualRuntime() {
return actualRuntime;
}

public void setActualRuntime(int actualRuntime) {
this.actualRuntime = actualRuntime;
}

synchronized void pleaseStop() {
running = false;
}
Expand All @@ -23,15 +32,15 @@ synchronized protected boolean shouldRun() {
protected int getBurstTime() {
return DescriptionTokenizer.getBurst(description);
}

protected String getJobName() {
return name;
return name;
}

protected int getInit() {
return DescriptionTokenizer.getInit(description);
}

public void run() {
running = true;
System.out.println("beginning of run " + name + " " + description);
Expand Down
2 changes: 2 additions & 0 deletions JobTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public JobTimer(Job target, int msecs) {
}

public void run() {
long jobStartTime = System.currentTimeMillis();
try {
Thread.sleep(msecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
myJob.pleaseStop();
myJob.setActualRuntime((int) (System.currentTimeMillis() - jobStartTime));
}
}
9 changes: 5 additions & 4 deletions Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ void makeRun() {
}
}

void addCompletedJob(Job job) {
void addCompletedJob(Job job) {
completedJobs.add(job);
}

public void printGannt() {
for (Job job: completedJobs) {
System.out.println("job id " + job.getBurstTime() + " job name: " + job.getJobName() + " job init: " + job.getInit());
}
for (Job job : completedJobs) {
System.out.println("job id " + job.getActualRuntime() + " job name: " + job.getJobName() + " job init: "
+ job.getInit());
}
}
}
3 changes: 1 addition & 2 deletions SystemSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public void run() {
}

public long relativeTime() {
long currentTime = System.currentTimeMillis();
return currentTime - startTime;
return System.currentTimeMillis() - startTime;
}

public void noMoreJobsToSubmit() {
Expand Down

0 comments on commit a94db77

Please sign in to comment.