GithubHelp home page GithubHelp logo

marvinjason / cpuscheduler Goto Github PK

View Code? Open in Web Editor NEW
50.0 4.0 25.0 117 KB

Java implementation of 6 CPU scheduling algorithms

Java 100.00%
java algorithm cpu-scheduling-algorithms library java-swing

cpuscheduler's Introduction

CPUScheduler

Java implementation of 6 CPU scheduling algorithms: First Come First Serve (FCFS), Shortest Job First (SJF), Shortest Remaining Time (SRT), Priority Non-preemptive (PSN), Priority Preemptive (PSP), and Round Robin (RR).

Usage

Instantiate a CPUScheduler object of the algorithm

CPUScheduler fcfs = new FirstComeFirstServe();

Add a new Row for every job queued

fcfs.add(new Row("P1", 0, 5));
fcfs.add(new Row("P2", 2, 4));
fcfs.add(new Row("P3", 4, 3));
fcfs.add(new Row("P4", 6, 6));

Call the process method

fcfs.process();

Use the accessors

fcfs.getAverageWaitingTime();     // 3.5
fcfs.getAverageTurnAroundTime();  // 8.0

Round Robin

In the case of RoundRobin, you must first set a time quantum before calling process.

CPUScheduler rr = new RoundRobin();

rr.add(new Row("P1", 0, 5));
rr.add(new Row("P2", 2, 4));
rr.add(new Row("P3", 4, 3));
rr.add(new Row("P4", 6, 6));

rr.setTimeQuantum(2);
rr.process();

Rows

Using the object's getRows method will return a List of all queued Row. After process, each Row will reflect their respective computed waiting time and turnaround time.

CPUScheduler sjf = new ShortestJobFirst();
List<Row> rows;

sjf.add(new Row("P1", 0, 5));
sjf.add(new Row("P2", 2, 4));

rows = sjf.getRows();
rows.get(1).getWaitingTime();     // 0
rows.get(1).getTurnaroundTime();  // 0

sjf.process();

rows = sjf.getRows();
rows.get(1).getWaitingTime();     // 3
rows.get(1).getTurnaroundTime();  // 7

Timeline

Using the object's getTimeline method will return a List of Event which can be used to draw a Gantt chart. The timeline shows what job is being processed at the given time.

List<Event> timeline = fcfs.getTimeline();

for (Event event : timeline)
{
  System.out.println(event.getStartTime());
  System.out.println("|  " + event.getProcessName());
}

System.out.print(timeline.get(timeline.size() - 1).getFinishTime());

Result:

0
|  P1
5
|  P2
9
|  P3
12
|  P4
18

Example

An example can be found here.

Demo

A Java Swing application using the library is included within the project.

Screenshots

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

cpuscheduler's People

Contributors

marvinjason avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cpuscheduler's Issues

Missing Idle process status, Round Robin miscalculation

Context: I'm lazy and I was looking for a CPU scheduling app instead of taking the time to calculate everything manually.

This was working pretty well for small assignments, and I loved how it gave the waiting time and turnaround time too, besides the Gantt chart.

But just in case someone else is also using this app, take note it excludes when the process is currently idle, which messes up the calculations. Plus, I wouldn't rely on the RR algorithm too. It might be right for some of you, but it's best to double-check your work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.