com.jimweller.cpuscheduler
Class CPUScheduler

java.lang.Object
  extended bycom.jimweller.cpuscheduler.CPUScheduler

public class CPUScheduler
extends java.lang.Object

CPUScheduler runs a simulation of one of four different scheduling algorithms (FCFS,SJF,ROUNDROBIN,PRIORITY). It can be set to run the whole simulation automatically in one fell swoop, or the programmer can imcrement on a step by step basis.

Version:
0.50
Author:
Jim Weller

Field Summary
(package private)  int activeIndex
          The index into the vector/array/readyQueue.
(package private)  Process activeJob
          A reference to the currently active job.
(package private)  int algorithm
          The algorithm to use for this simulation.
(package private)  java.util.Vector allProcs
          The collection of all processes involved in this simulation.
(package private)  long busy
          The amount of elapsed time that the CPU was kept busy.
(package private)  long currentTime
          This simulates elapsed time.
(package private) static int DEF_PROC_COUNT
          The default number of processes to randomly generate.
static int FCFS
          A constant for use in specifying the First Come First Serve scheduling algorithm
(package private)  long idle
          The amount of elapsed idle time.
(package private)  java.util.Vector jobQueue
          The collection of all jobs that will be used
(package private)  int maxResponse
           
(package private)  int maxTurn
           
(package private)  int maxWait
           
(package private)  double meanResponse
           
(package private)  double meanTurn
           
(package private)  double meanWait
           
(package private)  int minResponse
           
(package private)  int minTurn
           
(package private)  int minWait
           
(package private)  boolean preemptive
          Whether to use premption for the SJF and Priority algorithms.
(package private)  boolean priority
          Whether to use priority weights for the round robin algorithm.
static int PRIORITY
          A constant for use in specifying the Priority Queue scheduling algorithm
(package private)  int procsIn
          The number of jobs submitted for execution.
(package private)  int procsOut
          the number of jobs that have been executed to completion.
(package private)  long quantum
          for use in the round robin algorithm.
(package private)  long quantumCounter
          A count down to when to interrupt a process because it's timeslice is over.
(package private)  java.util.Vector readyQueue
          The collection of all jobs that have arrived and require CPU time.
static int ROUNDROBIN
          A constant for use in specifying the Round Robin scheduling algorithm
(package private)  double sDevResponse
           
(package private)  double sDevTurn
           
(package private)  double sDevWait
           
static int SJF
          A constant for use in specifying the Shortes Job First scheduling algorithm
(package private)  long turnCounter
          Only for the priority round robin algorithm, this variable keeps track of the number of consecutive timeslices a process has consumed.
 
Constructor Summary
(package private) CPUScheduler()
          Default constructor which builds DEF_PROC_COUNT randomly generated processes and loads them into the job queue
(package private) CPUScheduler(java.io.File filename)
          Articulate constructor that reads the process data from a file.
(package private) CPUScheduler(java.lang.String filename)
          Articulate constructor that reads the process data from a file.
(package private) CPUScheduler(java.util.Vector ap)
          Articulate constructor that allows the programmer to design his/her own Vector of processes and use them in the scheduler
 
Method Summary
(package private)  void buildRandomQueue()
          Empty and populate a CPUScheduler
(package private)  void cleanUp()
          Purge the runtime queues
(package private)  void Dispatch()
          Actually run the active job and wait the rest of them
(package private)  Process findEarliestJob(java.util.Vector que)
          FCFS: Get the job that got here first
(package private)  Process findLoftiestJob(java.util.Vector que)
          find the job with the highest priority In case of tie take first in the queue
(package private)  Process findNextJob(java.util.Vector que)
          RR: get the next job we should run (could be the one we're running).
(package private)  Process findShortestJob(java.util.Vector que)
          SJF: Locate the smallest job in a queue
 Process getActiveProcess()
          Get the Process that is actively being executed
 int getAlgorithm()
          Get the value of algorithm.
 java.lang.String getAlgorithmName()
          Get a string with the current algorithm's name
 long getBusyTime()
          Get the amount of time the CPU has been used so far.
 long getIdleTime()
          Get the number of idle cpu cycles.
 java.util.Vector getJobs()
          Get all jobs
 double getLoad()
          Get the system load.
 int getMaxResponse()
          Get the maximum process response time
 int getMaxTurn()
          Get the maximum process turn around time
 int getMaxWait()
          Get the maximum process wait time
 double getMeanResponse()
          Get the mean process response time
 double getMeanTurn()
          Get the mean process turn around time
 double getMeanWait()
          Get the mean process wait time
 int getMinResponse()
          Get the minimum process response time
 int getMinTurn()
          Get the minimum process turn around time
 int getMinWait()
          Get the minimum process wait time
 boolean getPreemption()
          Get the value of preemptive.
 boolean getPriority()
          Get the value of priority.
 long getProcsIn()
          Get the number of recieved jobs.
 long getProcsOut()
          Get the number of completed processes .
 long getQuantum()
          Get the value of quantum.
 double getStdDevResponse()
          Get the standard deviation in process response time
 double getStdDevTurn()
          Get the standard deviation in process turn around time
 double getStdDevWait()
          Get the standard deviation in process wait time
 long getTotalTime()
          Get the total time this simulation has been running.
private  void harvestStats()
          Loop through the job queue and grab important statistics
 void LoadJobQueue(java.util.Vector jobs)
          Load all the jobs into the job queue and setup their arrival times
(package private)  void LoadReadyQueue()
          Check for new jobs.
 boolean nextCycle()
          Just run one cycle of the simulation.
 void print()
          Dump to terminal.
 void printCSV()
          kindof ugly table to import into spreadsheet.
 void printCSV(java.io.PrintWriter pw)
          kindof ugly table to import into spreadsheet.
 void printReadyQueue()
          Dump ready queue to terminal.
 void printTable()
          kindof nice looking table.
(package private)  void PurgeJobQueue()
          Get rid of jobs that are done
(package private)  void PurgeReadyQueue()
          Remove finished jobs.
 void restore()
          Restore time and statisitic variables to their defaults.
(package private)  void RunFCFS(java.util.Vector jq)
          Do the FCFS scheduling algorithm
(package private)  void RunPriority(java.util.Vector jq)
          Do the Priority scheduling algorithm
(package private)  void RunRoundRobin(java.util.Vector jq)
          Do the RR scheduling algorithm
(package private)  void RunSJF(java.util.Vector jq)
          Do the SJF scheduling algorithm.
(package private)  void Schedule()
          Use the appropriate scheduler to choose the next process.
 void setAlgorithm(int algo)
          Set the value of algorithm.
 void setPreemption(boolean v)
          Set the value of preemptive.
 void setPriority(boolean v)
          Set the value of priority.
 void setQuantum(long v)
          Set the value of quantum.
 void Simulate()
          Run the whole simulation in one while loop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FCFS

public static final int FCFS
A constant for use in specifying the First Come First Serve scheduling algorithm

See Also:
Constant Field Values

SJF

public static final int SJF
A constant for use in specifying the Shortes Job First scheduling algorithm

See Also:
Constant Field Values

PRIORITY

public static final int PRIORITY
A constant for use in specifying the Priority Queue scheduling algorithm

See Also:
Constant Field Values

ROUNDROBIN

public static final int ROUNDROBIN
A constant for use in specifying the Round Robin scheduling algorithm

See Also:
Constant Field Values

DEF_PROC_COUNT

static final int DEF_PROC_COUNT
The default number of processes to randomly generate. The programmer can use the articulate constructor to build their own process set of any lenghth

See Also:
Constant Field Values

currentTime

long currentTime
This simulates elapsed time.


idle

long idle
The amount of elapsed idle time.


busy

long busy
The amount of elapsed time that the CPU was kept busy.


quantum

long quantum
for use in the round robin algorithm. It is the timeslice each process gets


quantumCounter

long quantumCounter
A count down to when to interrupt a process because it's timeslice is over.


turnCounter

long turnCounter
Only for the priority round robin algorithm, this variable keeps track of the number of consecutive timeslices a process has consumed.


procsIn

int procsIn
The number of jobs submitted for execution.


procsOut

int procsOut
the number of jobs that have been executed to completion.


preemptive

boolean preemptive
Whether to use premption for the SJF and Priority algorithms.


priority

boolean priority
Whether to use priority weights for the round robin algorithm.


algorithm

int algorithm
The algorithm to use for this simulation.


allProcs

java.util.Vector allProcs
The collection of all processes involved in this simulation. Extraneous now but handy for debugging.


jobQueue

java.util.Vector jobQueue
The collection of all jobs that will be used


readyQueue

java.util.Vector readyQueue
The collection of all jobs that have arrived and require CPU time.


activeJob

Process activeJob
A reference to the currently active job. The cpu changes this reference to different jobs in the ready queue using the respective algorithm's criteria


activeIndex

int activeIndex
The index into the vector/array/readyQueue.


minWait

int minWait

maxWait

int maxWait

meanWait

double meanWait

sDevWait

double sDevWait

minResponse

int minResponse

maxResponse

int maxResponse

meanResponse

double meanResponse

sDevResponse

double sDevResponse

minTurn

int minTurn

maxTurn

int maxTurn

meanTurn

double meanTurn

sDevTurn

double sDevTurn
Constructor Detail

CPUScheduler

CPUScheduler()
Default constructor which builds DEF_PROC_COUNT randomly generated processes and loads them into the job queue


CPUScheduler

CPUScheduler(java.util.Vector ap)
Articulate constructor that allows the programmer to design his/her own Vector of processes and use them in the scheduler


CPUScheduler

CPUScheduler(java.lang.String filename)
Articulate constructor that reads the process data from a file.

Parameters:
filename - a string containing the file to open

CPUScheduler

CPUScheduler(java.io.File filename)
Articulate constructor that reads the process data from a file.

Parameters:
filename - A File object to read data from
Method Detail

buildRandomQueue

void buildRandomQueue()
Empty and populate a CPUScheduler


Schedule

void Schedule()
Use the appropriate scheduler to choose the next process. Then dispatch the process.


Dispatch

void Dispatch()
Actually run the active job and wait the rest of them


RunFCFS

void RunFCFS(java.util.Vector jq)
Do the FCFS scheduling algorithm


RunSJF

void RunSJF(java.util.Vector jq)
Do the SJF scheduling algorithm.


RunPriority

void RunPriority(java.util.Vector jq)
Do the Priority scheduling algorithm


RunRoundRobin

void RunRoundRobin(java.util.Vector jq)
Do the RR scheduling algorithm


findNextJob

Process findNextJob(java.util.Vector que)
RR: get the next job we should run (could be the one we're running).


findShortestJob

Process findShortestJob(java.util.Vector que)
SJF: Locate the smallest job in a queue


findEarliestJob

Process findEarliestJob(java.util.Vector que)
FCFS: Get the job that got here first


findLoftiestJob

Process findLoftiestJob(java.util.Vector que)
find the job with the highest priority In case of tie take first in the queue


harvestStats

private void harvestStats()
Loop through the job queue and grab important statistics


LoadReadyQueue

void LoadReadyQueue()
Check for new jobs.


PurgeReadyQueue

void PurgeReadyQueue()
Remove finished jobs.


PurgeJobQueue

void PurgeJobQueue()
Get rid of jobs that are done


LoadJobQueue

public void LoadJobQueue(java.util.Vector jobs)
Load all the jobs into the job queue and setup their arrival times


print

public void print()
Dump to terminal.


printReadyQueue

public void printReadyQueue()
Dump ready queue to terminal.


printTable

public void printTable()
kindof nice looking table. Java sucks for text formatting. Printf?


printCSV

public void printCSV()
kindof ugly table to import into spreadsheet.


printCSV

public void printCSV(java.io.PrintWriter pw)
kindof ugly table to import into spreadsheet.


getPreemption

public boolean getPreemption()
Get the value of preemptive.

Returns:
Value of preemptive.

setPreemption

public void setPreemption(boolean v)
Set the value of preemptive.

Parameters:
v - Value to assign to preemptive.

setAlgorithm

public void setAlgorithm(int algo)
Set the value of algorithm.

Parameters:
algo - The algorithm to use for this simualtion.

getAlgorithm

public int getAlgorithm()
Get the value of algorithm.

Returns:
Value of algorithm.

getIdleTime

public long getIdleTime()
Get the number of idle cpu cycles.

Returns:
Number of idle cpu cycles.

getTotalTime

public long getTotalTime()
Get the total time this simulation has been running.

Returns:
total running time.

getBusyTime

public long getBusyTime()
Get the amount of time the CPU has been used so far.

Returns:
Busy cpu cycles.

getQuantum

public long getQuantum()
Get the value of quantum.

Returns:
Value of quantum.

setQuantum

public void setQuantum(long v)
Set the value of quantum.

Parameters:
v - Value to assign to quantum.

getPriority

public boolean getPriority()
Get the value of priority.

Returns:
Value of priority.

setPriority

public void setPriority(boolean v)
Set the value of priority.

Parameters:
v - Value to assign to priority.

getProcsOut

public long getProcsOut()
Get the number of completed processes .

Returns:
Value of procsOut.

getProcsIn

public long getProcsIn()
Get the number of recieved jobs.

Returns:
Value of procsOut.

getLoad

public double getLoad()
Get the system load.

Returns:
The current sysetm load which is input processes over output processes.

getActiveProcess

public Process getActiveProcess()
Get the Process that is actively being executed


Simulate

public void Simulate()
Run the whole simulation in one while loop


nextCycle

public boolean nextCycle()
Just run one cycle of the simulation. This represents one time unit.

Returns:
a boolean that is true if more cycles remain to be run.

cleanUp

void cleanUp()
Purge the runtime queues


restore

public void restore()
Restore time and statisitic variables to their defaults. Also restores all processes to original state and reloads the queues. Leavs algorithm configurations alone an other state variables.


getJobs

public java.util.Vector getJobs()
Get all jobs

Returns:
Vector of all Processes

getMeanWait

public double getMeanWait()
Get the mean process wait time

Returns:
an int containting the mean wait

getMinWait

public int getMinWait()
Get the minimum process wait time

Returns:
an int containting the minimum wait

getMaxWait

public int getMaxWait()
Get the maximum process wait time

Returns:
an int containting the maximum wait

getStdDevWait

public double getStdDevWait()
Get the standard deviation in process wait time

Returns:
an int containting the standard deviation for wait

getMeanResponse

public double getMeanResponse()
Get the mean process response time

Returns:
an int containting the mean response

getMinResponse

public int getMinResponse()
Get the minimum process response time

Returns:
an int containting the minimum response

getMaxResponse

public int getMaxResponse()
Get the maximum process response time

Returns:
an int containting the maximum response

getStdDevResponse

public double getStdDevResponse()
Get the standard deviation in process response time

Returns:
an int containting the standard deviation for response

getMeanTurn

public double getMeanTurn()
Get the mean process turn around time

Returns:
an int containting the mean turn around

getMinTurn

public int getMinTurn()
Get the minimum process turn around time

Returns:
an int containting the minimum turn around

getMaxTurn

public int getMaxTurn()
Get the maximum process turn around time

Returns:
an int containting the maximum turn around

getStdDevTurn

public double getStdDevTurn()
Get the standard deviation in process turn around time

Returns:
an int containting the standard deviation for turn around

getAlgorithmName

public java.lang.String getAlgorithmName()
Get a string with the current algorithm's name

Returns:
String containing the currently running algorithm's name