Written by Sai Sameera Thota on March 31, 2013 in Java > Programming

Java Program to implement First Come First Serve (FCFS) Scheduling

GET ALERTS:

Get our Latest updates delivered to your mailbox!

First Come First Serve (FCFS) is a method of load balancing to achieve the quality of service. The thread which comes first into the Process queue is served first. You can also think of this as First in First out (FIFO). The process which comes first is served first regardless of its burst time.

For example: If there are three processes namely p1, p2 and p3 having burst times 10, 14, 5 respectively and they arrive in the order p2, p1, p3. First p2(0) is served then p1(14) and then p3(14+10) is served i.e., p3 is served after 24 units.

FCFS Java Program

import java.util.*;
class Fcfs
{
	public static void main(String[] args)
	{
		int id[]=new int[20];
		int btime[]=new int[20];
		int wtime[]=new int[20];
		int total=0;
		float avg;
		Scanner sn = new Scanner(System.in);
		System.out.print("\nEnter the number of processes : ");
		int n = sn.nextInt();
		for (int i=0;i		{
			System.out.println();
			System.out.print("Enter the process ID of process "+(i+1)+" : ");
			id[i]=sn.nextInt();
			System.out.print("Enter the burst time of process "+(i+1)+" : ");
			btime[i]=sn.nextInt();
		}
		wtime[0]=0;
		for (int i=1;i		{
			wtime[i]=wtime[i-1]+btime[i-1];
			total=total+wtime[i];
		}
		avg=(float)total/n;
		System.out.println("\nProcess_ID\tBurst_time\tWait_time");
		for(int i=0;i<n;i++)
		{
			System.out.println(id[i]+"\t\t"+btime[i]+"\t\t"+wtime[i]);
		}
		System.out.println("\nTotal wait time: "+total+"\nAverage wait time: "+avg);
	}

}

Output:
fcfs-java

{ 1 comment… read it below or add one }

gayathri January 13, 2014 at 7:33 pm

i want to how to create own coding in java give some idea for me
……………………………………………………..

Reply

Leave a Comment

Previous post:

Next post: