Solved

first come first serve in java

Posted on 2010-08-17
5
1,181 Views
Last Modified: 2013-11-23
Can any1 provide a sample code of implementing first come first serve in java?

Lets assume that a tick is the minimum amount of time that CPU spends on one job before switching. The probabily of a job arriving between any two ticks is 0.2, the amount of work a job requires is randomly selected between 1 and 15 ticks. Finally keep generating jobs until a total of 100 jobs have arrived per run.

thnx
0
Comment
Question by:harryrei
5 Comments
 
LVL 10

Accepted Solution

by:
Hegemon earned 168 total points
ID: 33458321
You can use one of the classes implementing the Queue interface.http://cupi2.uniandes.edu.co/site/images/recursos/javadoc/j2se/1.5.0/docs/api/java/util/Queue.html
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 166 total points
ID: 33499523
"THIS IS A PROGRAM ON FIRST COME FIRST SERVED PROCESS SCHEDULING ALGORITHAM OF TYPE NONPREEMPTIVE SCHEDULING ALGORITHAM.THIS ALGORITHAM HELPS YOU TO ANALYSE THE FCFS CLEARLY AND AND ALSO CALCULATES SOME PARAMETERS WHICH ARE GOING TO BE MENTIONED."
   http://www.sourcecodesworld.com/source/show.asp?ScriptID=928

There are some good lectures on scheduling including FCFS here:

http://www.academicearth.org/courses/operating-systems-and-system-programming

Lecture 10: (latter 2/3 begins scheduling)
   http://www.academicearth.org/lectures/deadlock-continued--thread-scheduling

Lecture 11: continuation
http://www.academicearth.org/lectures/scheduling-continued--protection-kernel-and-address-spaces

Handouts for the these lectures:
http://www-inst.cs.berkeley.edu/~cs162/fa09/Lectures/lec10-scheduling.pdf
http://www-inst.cs.berkeley.edu/~cs162/fa09/Lectures/lec11-protection.pdf
0
 
LVL 2

Assisted Solution

by:matstein
matstein earned 166 total points
ID: 35967234
The above posters have already addressed the Queue issue if you need a hint with the job generation part of your question you can have something that looks like this


   
int ticks = 0;
int job_ticks;
for (i=0;i<100;i++)
 while(Random.nextInt(4))
 {
  ticks++; //20% chance of generating a job in this tick.
  }
  ticks++;
  job_ticks = (Random.nextInt(14)+1);
  Queue.add(job_ticks);
}
System.out.println("100 jobs where generated in "+ticks" ticks);

Open in new window


0
 
LVL 100

Expert Comment

by:mlmcc
ID: 36235309
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
table example 4 32
hibernate example for saving data 19 52
How do sunrise and sunset times change with altitude 14 35
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question