Objectives: To practice programming an application with multiple threads of execution and synchronizing their access to necessary shared objects.

Description: In this programming assignment you will simulate the pump management system for a water treatment plant like the one depicted here: See image.

This example water treatment plant has five pumping stations (S0 – S4), each of which has an input and output pipe connecting to lines (P0 – P4) that go elsewhere in the plant. Resources were limited when building the plant so each pipe going to the rest of the facility must be shared between two pumping stations. Since each station simultaneously needs an input and output connection to function, access to the shared lines must be strictly regulated. Flow direction in not important in our simulation.

You have been hired to design a simulator for a new water treatment plant being built with the same design, but possibly fewer/more stations. You are to implement this simulator in Java and have each station function in its own thread. A station’s workload is the amount of time that a station needs to have access to the input and output pipes during the simulation. Once a station is granted access to both pipes it calls its doWork()method during which it will attempt to flow water down each pipe (of course it must verify that it has access and isn’t in conflict with another station). After the flow-in and flow-out methods are run, the workload of the station is reduced by 1 and the station releases both pipes and signals waiting stations that the pipes are available. After executing a flow and releasing its pipes, a station should sleep for some random period of time. A station’s thread stops running when its workload reaches 0.


  • Do not use a monitor to control the synchronization in your program (i.e., do not use the Java synchronize statement).

Input Specification

Your program must initially read from a text file (config.txt) to gather configuration information for the simulator. The first line of the text file will be the number of stations to use during the simulation. Afterwards, there will be one line for each station. These lines will hold the amount of work each station needs to process. Only use integers in your configuration file, decimals will not be needed.

Output Specification

Your simulator must output the following text to let the user know what the simulator is doing in each of these situations:

  • An input connection is set: Station X: In-Connection set to pipe n
  • An output connection is set: Station X: Out-Connection set to pipe n
  • A stations workload is set: Station X: workload set to n
  • A station is granted access to a pipe: Station X: granted access to pipe n
  • A station is releasing access to a pipe: Station X: released access to pipe n
  • A station has completed its workload: Station X: Workload successfully completed.
  • A station successfully flows water down a pipe: Station X: successfully flows on pipe n
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.