Skip to content Skip to sidebar Skip to footer

Round Robin Scheduling Program In Java With Gantt Chart

Round Robin Scheduling

Introduction

Round Robin Scheduling is a CPU scheduling algorithm that is widely used in computer operating systems. It is a pre-emptive scheduling algorithm that is designed to provide fair CPU time to each process in the system. In this article, we will discuss the Round Robin Scheduling Program in Java with Gantt Chart.

What is Round Robin Scheduling?

Round Robin Scheduling is a CPU scheduling algorithm that is designed to provide fair CPU time to each process. In this algorithm, each process is given a fixed time slot or quantum to execute. If the process completes its execution within the given time slot, it is removed from the CPU and the next process is executed. If the process does not complete its execution within the given time slot, it is pre-empted and moved to the back of the ready queue.

Gantt Chart

How Round Robin Scheduling Works?

In Round Robin Scheduling, each process is given a fixed time slot or quantum to execute. The time slot is decided by the system and is usually a small fraction of a second. When the system starts executing, the first process in the ready queue is selected and is given the first time slot. If the process completes its execution within the given time slot, it is removed from the CPU and the next process in the ready queue is selected. If the process does not complete its execution within the given time slot, it is pre-empted and moved to the back of the ready queue. The next process in the ready queue is then selected and given the next time slot.

Round Robin Scheduling Program in Java

Here's a simple Round Robin Scheduling Program in Java:

import java.util.*;class RoundRobinScheduling {public static void main(String args[]) {Scanner sc = new Scanner(System.in);System.out.print("Enter the number of processes: ");int n = sc.nextInt();int bt[] = new int[n];int wt[] = new int[n];int tat[] = new int[n];int quantum;System.out.print("Enter the time quantum: ");quantum = sc.nextInt();System.out.println("Enter burst time for each process: ");for(int i = 0; i < n; i++) {System.out.print("P" + (i+1) + ": ");bt[i] = sc.nextInt();}int t = 0;int rp[] = new int[n];for(int i = 0; i < n; i++) {rp[i] = bt[i];}while(true) {boolean done = true;for(int i = 0; i < n; i++) {if(rp[i] > 0) {done = false;if(rp[i] > quantum) {t += quantum;rp[i] -= quantum;} else {t += rp[i];wt[i] = t - bt[i];rp[i] = 0;}}}if(done == true) {break;}}for(int i = 0; i < n; i++) {tat[i] = bt[i] + wt[i];}float avgwt = 0, avgtat = 0;for(int i = 0; i < n; i++) {avgwt += wt[i];avgtat += tat[i];}avgwt /= n;avgtat /= n;System.out.println("Process\tBurst Time\tWaiting Time\tTurnaround Time");for(int i = 0; i < n; i++) {System.out.println("P" + (i+1) + "\t" + bt[i] + "\t\t" + wt[i] + "\t\t" + tat[i]);}System.out.println("Average Waiting Time: " + avgwt);System.out.println("Average Turnaround Time: " + avgtat);}}

How to Run Round Robin Scheduling Program in Java?

To run the Round Robin Scheduling Program in Java, follow these steps:

  1. Open a text editor and paste the above code.
  2. Save the file with a .java extension.
  3. Open a command prompt and navigate to the directory where the file is saved.
  4. Compile the program using the following command: javac RoundRobinScheduling.java
  5. Run the program using the following command: java RoundRobinScheduling

What is Gantt Chart?

A Gantt chart is a type of bar chart that is used to illustrate a project schedule. It is named after Henry Gantt, who first introduced the chart in the early 1900s. A Gantt chart shows the start and finish dates of the different tasks or activities that make up a project. It also shows the dependencies between the tasks and the progress of the project over time.

Round Robin Scheduling Program in Java with Gantt Chart

Here's a Round Robin Scheduling Program in Java with Gantt Chart:

Round Robin Scheduling Program In Java With Gantt Chart

Conclusion

In this article, we discussed the Round Robin Scheduling Program in Java with Gantt Chart. Round Robin Scheduling is a CPU scheduling algorithm that is designed to provide fair CPU time to each process in the system. We also discussed how Round Robin Scheduling works and how to run the Round Robin Scheduling Program in Java. A Gantt chart is a type of bar chart that is used to illustrate a project schedule. It is named after Henry Gantt, who first introduced the chart in the early 1900s. We also provided a Round Robin Scheduling Program in Java with Gantt Chart.

Related video of Round Robin Scheduling Program In Java With Gantt Chart