Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One interesting class of applications of concurrent programming is simulation, in which a program simulates a real-world system by using individual threads to simulate its

One interesting class of applications of concurrent programming is simulation, in which a program simulates a real-world system by using individual threads to simulate its individual components. For this project, we will be simulating a bank, having some number of tellers. Each customer arrives at the bank, waits in a single line until a teller becomes free, and then goes to that teller to transact his/her business, leaving the bank when his/her business is done. In this case, a thread simulates each individual customer.

The major parameters of this system are: the number of tellers, the rate at which new customers arrive (specified as an average interval between arrivals), and the average time it takes to service a customer.

Clearly:

1. If (average inter-arrival time) >> (average service time) / (# of tellers) then customers will seldom stand in line, but tellers will often not be productively employed.

2. If (average inter-arrival time) < (average service time) / (# of tellers) then the waiting line will grow without limit and customers will become very angry.

3. If (average inter-arrival time) = (average service time) / (# of tellers) then the system will eventually reach a steady state with a fairly constant waiting line length.

The value for each of these three parameters supplied to the assignments program should be chosen to satisfy number 3 above so the tellers are productive and the customers dont become angry. Therefore, to test your program, choose values for two of the parameters in the equation of number 3 and then compute the value of the third parameter. You can generate several different sets of values for the three parameters to test your program.

For this project, you write a program that simulates this system. At startup, your program will accept the three parameters mentioned above plus the length of time to run the simulation. All times will be entered in seconds. To avoid having to run the program for an entire day, we will simulate ten seconds of "simulated world" time by one second of actual program run time.

The simulation will proceed as follows:

1. One thread will be responsible for creating new customers at random intervals, such that the average time between new customers is equal to the specified parameter. It will exist throughout the simulation.

2. Created when a customer arrives, a unique thread simulates each customer, works its way through the bank, and then terminates.

3. A general semaphore that uses a FIFO queue will simulate the waiting line.

4. The semaphore initializes to the number of tellers. If there are n tellers, then the first n customers doing an acquire() on this semaphore will be able to proceed without delay.

5. When each customer thread enters the bank, he/she will do a acquire() on this semaphore. When he/she finishes being served, he/she will do a release(), allowing another customer to pass the semaphore and use the teller.

1. Create a driver class and make the name of the driver class Assignment2 and it should only contain only one method: public static void main(String args[]). The main method receives, via the command line arguments, these four parameters in exactly this order: 1. The number of tellers. 2. The mean (average) time between arrivals. 3. The mean (average) service time. 4. The length of time to run the simulation. The main method itself should be fairly short creating and then starting the thread which generates the customer threads.

2. The thread that generates the customer threads can be structured as follows: while (the end of the simulation has not yet been reached) do begin sleep() a random amount of time, based on inter-arrival mean; if (simulation end time not yet reached) then create a customer thread; end;

3. A customer thread can be structured as follows: ? Get next available customer number. ? Increment number of customers in bank. ? Report arrival and save arrival time. ? Get in line (i.e., wait on semaphore.) ? Done waiting; calculate waiting time. ? Report starting to be served. ? Sleep() a random amount of time, based on service time mean. ? Report leaving the bank. ? Update global statistics. ? Decrement number of customers in bank. ? Exit.

4. All of the parameter time values represent simulated world seconds, with ten simulated world seconds simulated by one second of actual program run time. Therefore, the parameter time values should be a multiple of 10.

5. To obtain a random number using the mean time between arrivals (inter-arrival time) or the mean service time youll use the random number generator implemented in this class: Random_Int_Mean.java which youll download to include in your assignments code. Since one second of actual program run time simulates ten simulated world seconds, be sure to divide time parameters by 10 and use that value to pass to the random_int() method since the return value of the random_int method is the number of real world seconds the particular thread will sleep.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

2 What supply is and what affects it.

Answered: 1 week ago